A callback that will immutably update an object according to a given path.
yarn add use-deep-update-callback
import React, { useState } from 'react'
import { useDeepUpdateCallback } from 'use-deep-update-callback'
const Example = () => {
const [state, setState] = useState({ inputValues: { nameInput: { value: '' } } });
const onChange = useDeepUpdateCallback(state, ['inputValues', 'nameInput', 'value'], setState);
return (
<div>
<input value={state.inputValues.nameImput.value} onChange={event => onChange(event.target.value)} />
</div>
)
}
MIT © korbinancell
This hook is created using create-react-hook.