DEV Community

Cover image for Why useState??? and Some important basic things of React useState Hook,I have noticed....
Riyad Mahmud
Riyad Mahmud

Posted on

Why useState??? and Some important basic things of React useState Hook,I have noticed....

-----------------------------------------------

  • "useState" related to taking/getting a state and updatingState function for any updating state. Ex: const [count,setCount] = useState(0);
  • We can use any "premetive data" or "array object" for useState argument (argument not parameter)
  • "premetive data" is more preferable for beginner
  • "array object" is difficult to implement and understand the code for a beginner.
  • Implemented argument in useState function," "premetive data" or "array object" " return two this such an state and state updating function. Ex: const [count,setCount] = useState(0); //Here , "count" is a state and "setCount" is a state updating function. "0" is a premetive data.

-----------------------------------------------

Best of Luck all of you.....

Thanks to my loving teachers,
Sumit Saha, HM Nayem, Vishwash, Anisul Islam, Rabbil Hasan Rupom

Top comments (2)

Collapse
 
pengeszikra profile image
Peter Vivo
const [fooObject, setFooObject] = useState({});
Enter fullscreen mode Exit fullscreen mode

useState return two elements array give free to declare state and action ( value / setter ) names, in one step;

Collapse
 
riyadmahmud2021 profile image
Riyad Mahmud

Thanks,
I have told here, " such an state and state updating function. " .
I think updating means not only increment or decrement a state but also new value setting in a state.