gpt4 book ai didi

reactjs - 第 0 行 : Parsing error: Cannot read property 'map' of undefined

转载 作者:行者123 更新时间:2023-12-03 07:26:46 32 4
gpt4 key购买 nike

目前在我的客户端启动服务器,上面的错误是我一直在
得到。我正在使用 Typescript、React、ESlint。由于此错误,我似乎无法前进
一直困扰着我。 Eslint 的 github 页面也没有太大帮助。

在我创建 useMutation 组件并将其导出到
索引.ts,
不知道如何摆脱这个错误。

Below is my package.json
    {
"name": "tinyhouse_client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.0",
"@typescript-eslint/parser": "^3.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "~2.23.0"
},
"resolutions": {
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"@typescript-eslint/typescript-estree": "^2.23.0"
},
"scripts": {
"start": "react-scripts start",
" build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
**strong text** "proxy": "http://localhost:9000"
}
Below is my index.ts
    export * from './server';
export * from './useQuery';
export * from './useMutation';
And my useMutation.ts
    import { useState } from 'react';
import { server } from './server';

interface State<TData> {
data: TData | null;
loading: boolean;
error: boolean;
}

type MutationTuple<TData, TVariables> = [
(variables?: TVariables | undefined) => Promise<void>,
State<TData>
];

export const useMutation = <TData = any, TVariables = any>(
query: string
): MutationTuple<TData, TVariables> => {
const [state, setState] = useState<State<TData>>({
data: null,
loading: false,
error: false,
})

const fetch = async (variables?: TVariables) => {
try {
setState({ data: null, loading: true, error: false });

const { data, errors } = await server.fetch<TData, TVariables>({ query, variables });
if (errors && errors.length) {
throw new Error(errors[0].message);
}

setState({ data, loading: false, error: false });
} catch (err) {
setState({ data: null, loading: false, error: true });
throw console.error(err);
}
}

return [fetch, state];
};

最佳答案

这是来自 eslint-typescript 吗?如果是这样,请检查您的 typescript 版本是否不是开发/夜间构建。

关于reactjs - 第 0 行 : Parsing error: Cannot read property 'map' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62079477/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com