Invalid hook call. Hooks can only be called inside of the body of a function component

后端 未结 14 1528
滥情空心
滥情空心 2020-12-03 09:25

I am new to React and Now I would like to show some record in the table and now I got this error. Help me, please.

Invalid hook call. Hooks can only b

14条回答
  •  感动是毒
    2020-12-03 10:05

    I had this issue when I used npm link to install my local library, which I've built using cra. I found the answer here. Which literally says:

    This problem can also come up when you use npm link or an equivalent. 
    In that case, your bundler might “see” two Reacts — one in application folder
    and one in your library folder. Assuming 'myapp' and 'mylib' are sibling folders,
    one possible fix is to run 'npm link ../myapp/node_modules/react' from 'mylib'.
    This should make the library use the application’s React copy.
    

    Thus, running the command: npm link ../../libraries/core/decipher/node_modules/react from my project folder has fixed the issue.

提交回复
热议问题