Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs ESLint没有';t建议使用有效的必要订户(CRA&x2B;TS&x2B;ESLint&x2B;Prettier)_Reactjs_Typescript_Create React App_Eslint_Prettier - Fatal编程技术网

Reactjs ESLint没有';t建议使用有效的必要订户(CRA&x2B;TS&x2B;ESLint&x2B;Prettier)

Reactjs ESLint没有';t建议使用有效的必要订户(CRA&x2B;TS&x2B;ESLint&x2B;Prettier),reactjs,typescript,create-react-app,eslint,prettier,Reactjs,Typescript,Create React App,Eslint,Prettier,当我试图创建自定义钩子时,我遇到了一些问题。 ESLint没有建议我订阅useEffect。(fetch没有被建议,我手动填充了它)我也尝试了eslint插件react钩子,它也不起作用 useEffect(() => { fetch(); }, [fetch]); 对useCallback也有同样的问题 自定义钩子的完整代码 import { useState, useEffect, useCallback } from "react"; import { server }

当我试图创建自定义钩子时,我遇到了一些问题。 ESLint没有建议我订阅useEffect。(fetch没有被建议,我手动填充了它)我也尝试了eslint插件react钩子,它也不起作用

useEffect(() => {
    fetch();
  }, [fetch]);
对useCallback也有同样的问题

自定义钩子的完整代码

import { useState, useEffect, useCallback } from "react";
import { server } from "./server";
interface State<TData> {
  data: TData | null;
}
export const useQuery = <TData = any>(query: string) => {
  const [state, setState] = useState<State<TData>>({
    data: null,
  });

  const fetch = useCallback(() => {
    const fetchApi = async () => {
      const { data } = await server.fetch<TData>({ query });
      setState({ data });
      console.log(`${data} loaded (useQuery hook)`);
    };
    fetchApi();
  }, [query]); // HERE

  useEffect(() => {
    fetch();
  }, [fetch]); // AND HERE

  return { ...state, refetch: fetch };
};
依赖性

"devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.0.2",
    "@typescript-eslint/parser": "^3.0.2",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.3",
    "prettier": "^2.0.5"
  }
"devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.0.2",
    "@typescript-eslint/parser": "^3.0.2",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.3",
    "prettier": "^2.0.5"
  }