I have
const [setEmail, email] = useState();
though when I call setEmail("[email protected]") it does not setEmail and it does not give an error message
code
alert("before email - yes)
setEmail([email protected])
alert("after email - no)
alert("after email - no)
never gets called? what the actual , no error message given either. and its not to do with @.com as when i call setEmail("sdsafs") it doesn’t work either.
2
Answers
I think the way you are using the useState hook is wrong. What does useState return? It returns a pair of values: the current state and a function that updates it. This is why we write const [count, setCount] = useState().The order is important here. You have named them the other way. try below,
also refer https://legacy.reactjs.org/docs/hooks-state.html for how to use useState hook
You should use
useState
hook properly. And it is not correct in the use of alert.