Video Tutorial The useState hook
In the previous chapters we saw that it was possible to define a component from a simple function.
function PrimaryButton ({children, ... props}) {
return
}
Unfortunately, before the release of react 16.8 it was not possible to use a state for this type of component. This problem was corrected with the appearance of a new API within react: the hooks API.
useState
Hooks provide a functional approach to state management.
function Counter () {
const (count, setCount) = useState (0);
const increment = function () {
setCount (n => n + 1)
}
return
}