簡體   English   中英

使用 typescript + 生成的核心用作 package 調用 graphql-codegen 查詢時,掛鈎調用無效

[英]Invalid hook calls when calling a graphql-codegen query with typescript + generated core used as a package

我正在使用帶有生成代碼的 npm package 和使用它的移動 package 的 Yarn 工作區。

嘗試從導入的查詢中撥打電話時,我收到無效的掛鈎調用。 在該組件中使用任何其他鈎子(即 useState)都可以正常工作。

我的手機 package 的 package.json 導入: "@workspace-library/core": "1.0.0",

我在 core/src 有一個 index.js 文件,它有:

export * from "./generated/graphql";
export { apollo, useAuth, withAuth };

我像這樣導入查詢:

import {
  useArticlesQuery
} from "@workspace-library/core";

const SidebarArticles: FunctionComponent<{ props: any }> = (props: any) => {
  const [test, setTest] = useState("false");
  const data = useArticlesQuery({
    fetchPolicy: "no-cache",
    notifyOnNetworkStatusChange: true,
  });

   return (
    <View>
      <Text>Heyhey</Text>
    </View>
  );
};

我可以在生成的/graphql.jsx 中看到 useArticlesQuery,以防萬一:

export function useArticlesQuery(baseOptions) { return ApolloReactHooks.useQuery(ArticlesDocument, baseOptions); }

環境:

  • 操作系統:Ubuntu
  • "@graphql-codegen/cli": "^1.13.1",
  • "@graphql-codegen/typescript": "^1.13.1",
  • "@graphql-codegen/typescript-operations": "^1.13.1",
  • "@graphql-codegen/typescript-react-apollo": "^1.13.1",
  • 紗線工作區

有問題的附加上下文錯誤:

Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
* /home/dogchef/Development/workspace-library/packages/core/node_modules/react/cjs/react.development.js:1589:4 in resolveDispatcher
* /home/dogchef/Development/workspace-library/packages/core/node_modules/react/cjs/react.development.js:1597:29 in useContext
* http://192.168.1.2:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:181621:41 in useBaseQuery
* /home/dogchef/Development/workspace-library/packages/core/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:550:18 in useQuery
* http://192.168.1.2:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:197883:37 in useArticlesQuery
* components/SidebarArticles.tsx:10:2 in SidebarArticles

我遇到了同樣的問題。 使用useQuery是有效的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM