close

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

Today We are Going To Solve Invalid hook call. Hooks can only be called inside of the body of a function component in reactjs. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix Invalid hook call. Hooks can only be called inside of the body of a function component Error?

  1. How to Fix Invalid hook call. Hooks can only be called inside of the body of a function component Error?

    To Fix Invalid hook call. Hooks can only be called inside of the body of a function component Error just Run the command. Here you have to run the below command to solve your error npm link <path_to_local_library>/node_modules/react

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

    To Fix Invalid hook call. Hooks can only be called inside of the body of a function component Error just Add this to your package.json. You have to just add this to your package.json "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" }

Solution 1 : Run the command

Here you have to run the below command to solve your error

npm link <path_to_local_library>/node_modules/react

Solution 2 : Add this to your package.json

You have to just add this to your package.json

"peerDependencies": {
   "react": ">=16.8.0",
   "react-dom": ">=16.8.0"
}

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read These Solutions

Leave a Comment