React Hook

This writing provides an overview and introduction of React Hook. 1. What is a Hook? Hooks allow function components to access React state and lifecycle features. Rules for using hooks: Only call hooks at the top level of your component. Only call hooks within React function components or custom hooks. import React, { useState, useEffect } from 'react' ; function TitleCount() { const [count, setCount] = useState( 0 ); useEffect(() => { document . title = ` You clicked ${count} times ` ; }, [count]); return < button onClick = {(prev) => setCount(prev + 1 )} >+</ button > ; } 2. useState() Hook The useState hook allows adding state to function components. It should be called at the top level of a component to manage its state. When useState is called, it returns an array with two values: currentState : The current state value. stateSetter : A function to update the state. initialState : Initial value. true, fa...