Everything you need to know about useState hook of React
A beginner's guide
Thread🧵👇
Hey👋
Hooks are powerful but confusing. Don't worry, I'll try to explain each hook in the easiest way in this thread series of React hooks
Let's start with useState, the most useful and simple hook in my opinion
Working with React hooks, first thing you need to do is to import the particular hook
It's quite easy👇
📌 import { useState } from "react";
useState hook takes a parameter as initial value of state and return an array having two values
- The first value is the current state
- The second value is the function that allow us to change our state
Let me show you the return value by printing it out on console👇
Now we know what useState hook return, it's time to destruct our value
const [currentState, setCurrentState] = useState(0);
🔹 currentState is the value of our state
🔹 setCurrentState is the function using which we can change our state value