DEV Community

Discussion on: Quick Tip - Memoizing change handlers in React Components

Collapse
 
robertbroersma profile image
Robert

Hey Dawson! Thanks for the reply. I realize this might be a bit late, but I think you could use a combination of useCallback and memoize:

const [state, setState] = useState(initialValues)

const handleChange = useCallback(memoize(key => value => {
  setState({ [key]: value })
}), [])

Perhaps there's a better or easier way using useReducer!