November 2019
Beginner
804 pages
20h 1m
English
The first React hook that we'll discover together is probably also the one that you'll use most: useState. As its name suggests, it enables function components to have/use internal state. React will maintain that internal state in-between the re-renders of the concerned components.
You can invoke the useState hook within a function component to define a single state variable, along with a function to update it.
Take a look at a simple example:
import React, {useState} from 'react';
export function Switch(props) {
const [currentSwitchStatus, switchStatus] = useState(false); return ( <div> <span>The switch ...Read now
Unlock full access