DEV Community

Discussion on: React hooks & the closure hell

Collapse
 
amsterdamharu profile image
Harm Meijer • Edited

React team actually discurrages this patern: reactjs.org/docs/hooks-faq.html#ho...

Instead of the pattern you use you can pass a callback to the state setter:

const handleClick = React.useCallback(() => {
  setValue(value => value + 1);
}, []);