Reputation: 55
what is the purpose of useState
?
what is it doing ? what is the value '0'?
what does useState
function returns ?
can we write anything in place of currentId
and setCurrentId
?
i am from java language . this whole syntax looks very weird . generally we write like this => int a = sum(b,c);
in java but in this case we have square brackets with two variables in it . what kind of thing is this ?
const [currentId, setCurrentId] = useState(0);
Upvotes: 0
Views: 63
Reputation: 269
useState is not from react-redux
, but React itself, it's called a hook
What you are doing is you are initializing a value, called currentId
with the value 0.
setCurrentId
is the function that you would use to update the state.
Yes you can write anything you want instead of those, for example
const [number, setNumber] = useState(0);
if(condition) setNumber(1)
Upvotes: 1