Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 549 Bytes

useSetState.md

File metadata and controls

24 lines (18 loc) · 549 Bytes

useSetState

React state hook that creates setState method which works similar to how this.setState works in class components—it merges object changes into current state.

Usage

import {useuseSetStateRaf} from 'react-use';

const Demo = () => {
  const [state, setState] = useSetState({});

  return (
    <div>
      <pre>{JSON.stringify(state, null, 2)}</pre>
      <button onClick={() => setState({hello: 'world'})}>hello</button>
      <button onClick={() => setState({foo: 'bar'})}>foo</button>
    </div>
  );
};