How to fix invalid Hook call error in react | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix invalid Hook call error in react

Im building a project with react and redux , but when I wrap my APP component with the PROVIDER HOOK from react-redux , I get an error (invalid Hook call error). Any ideas on how to fix it

23rd Jul 2021, 5:09 PM
Villain
Villain - avatar
14 Answers
0
Are you returned properly.
23rd Jul 2021, 5:41 PM
Kelvin Paul
Kelvin Paul - avatar
+ 6
Check out this code to study how react hook works with redux. https://code.sololearn.com/W8a21a131a17/?ref=app
23rd Jul 2021, 5:18 PM
Calviղ
Calviղ - avatar
+ 4
For react hook, all component must be in functional components. Convert all your class components to functional components
23rd Jul 2021, 5:14 PM
Calviղ
Calviղ - avatar
+ 4
Jsx only work from return statement of component function, e.g. const App = ()={ return ( {/* jsx here */} ) } Or const App = ()=>( {/* jsx here */} )
24th Jul 2021, 1:19 AM
Calviղ
Calviղ - avatar
+ 1
Kelvin Paul , I tried it on an online text editor it works fine, but when I try it on my local machine I get that error ( INVALID HOOK CALL )
23rd Jul 2021, 5:26 PM
Villain
Villain - avatar
+ 1
Kelvin Paul , I've literally ran out of ideas I made sure all dependencies were up to date , deleted node_modules folder again and ran *npm install* , still nothing , I'm using the latest versions of everything
23rd Jul 2021, 5:31 PM
Villain
Villain - avatar
+ 1
Bro can you please share your code?☺
23rd Jul 2021, 5:33 PM
Kelvin Paul
Kelvin Paul - avatar
0
Can you specify the error. I'm just guessing, just wrap that jsx using a function
23rd Jul 2021, 5:14 PM
Kelvin Paul
Kelvin Paul - avatar
0
Calviղ my component is a function based component
23rd Jul 2021, 5:27 PM
Villain
Villain - avatar
0
Dexter 🐺 bro according to the react official. I think you may imported more than one times the react file as script, or you were using old version. Please checkout.
23rd Jul 2021, 5:29 PM
Kelvin Paul
Kelvin Paul - avatar
0
It was a long line of code but I deleted most of it what I'm left with is import { Provider } from "react-redux" Import Store from "./Store" const App = ()=>{ <Provider store={Store} > <div> Hello world </div> </Provider> } export default App
23rd Jul 2021, 5:36 PM
Villain
Villain - avatar
0
Kelvin Paul , I was working on a auth system with Django , react and redux and some other stuff , but I was able to isolate the fault to this 👆👆
23rd Jul 2021, 5:38 PM
Villain
Villain - avatar
0
Kelvin Paul , the error arises immediately I wrap my APP component with PROVIDER
23rd Jul 2021, 5:39 PM
Villain
Villain - avatar
0
You might be breaking the rules of hooks : https://reactjs.org/warnings/invalid-hook-call-warning.html Or More likely , Maybe you have another copy of react in the same app. The doc has addressed this problem as well.
24th Jul 2021, 3:48 AM
Ćheyat
Ćheyat - avatar