React hooks in react library giving Invalid hook call error

后端 未结 6 1524
灰色年华
灰色年华 2021-02-12 13:17

I create a react library using https://www.npmjs.com/package/create-react-library And successfully used it on other React project. But when I tried to use react hooks functiona

6条回答
  •  我在风中等你
    2021-02-12 13:39

    I just ran into the same issue. I was able to fix it by pointing to the same react in my example app as in my library:

    App Structure

    Root

    • Example
      • package.json
    • src (library)
    • package.json

    So, from the example > package.json I changed react to be:

        "react": "link:../node_modules/react",
    

    This is much like the npm link listed above but it won't go away every time you npm install.

提交回复
热议问题