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
Caught this error: found solution.
For some reason, there were 2 onClick
attributes on my tag.
Be careful with using your or somebodies' custom components, maybe some of them already have onClick
attribute.
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.
I have just started using hooks and I got the above warning when i was calling useEffect inside a function:
Then I have to move the useEffect outside of the function as belows:
const onChangeRetypePassword = async value => {
await setRePassword(value);
//previously useEffect was here
};
//useEffect outside of func
useEffect(() => {
if (password !== rePassword) {
setPasswdMismatch(true);
}
else{
setPasswdMismatch(false);
}
}, [rePassword]);
Hope it will be helpful to someone !
Yesterday, I shortened the code (just added <Provider store={store}>
) and still got this invalid hook call problem. This made me suddenly realized what mistake I did: I didn't install the react-redux software in that folder.
I had installed this software in the other project folder, so I didn't realize this one also needed it. After installing it, the error is gone.
This error can also occur when you make the mistake of declaring useDispatch from react-redux the wrong way:
when you go:
const dispatch = useDispatch
instead of:
const dispatch = useDispatch();
(i.e remember to add the parenthesis)
You can convert class component to hooks,but Material v4 has a withStyles HOC. https://material-ui.com/styles/basics/#higher-order-component-api Using this HOC you can keep your code unchanged.