Introduction to Reack Hooks
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.
import React, { useState } from 'react'; function Example() { // Declare a new state variable, which we'll call "count" const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click me </button> </div> );}
This new function useState
is the first “Hook” we’ll learn about, but this example is just a teaser. Don’t worry if it doesn’t make sense yet!
Hooks solve a wide variety of seemingly unconnected problems in React that we’ve encountered over five years of writing and maintaining tens of thousands of components. Whether you’re learning React, use it daily, or even prefer a different library with a similar component model, you might recognize some of these problems