React hooks let you use the state in your components without using a class. You can write your components by using ES6 arrow functions. Let's take a look at how the previous counter example (mentioned in Props and the state section ) can be performed using React hooks. The hook function that lets you set a state value is called useState. It takes one argument, which is the initial value of the state. The following example code creates a state variable called count, and the initial value is zero.
The value of the state can now be updated by using the setCount function:
// count state with initial value 0
const [count, setCount] = useState(0);
The counter example now looks like the following when using setState. Here, we don't use the render() method because we are using a function instead of a component. The function just returns what we want to render:
import...