Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.03 KB

README.md

File metadata and controls

37 lines (25 loc) · 1.03 KB

use-deep-update-callback

A callback that will immutably update an object according to a given path.

NPM JavaScript Style Guide

Install

yarn add use-deep-update-callback

Usage

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>
  )
}

License

MIT © korbinancell


This hook is created using create-react-hook.