Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 689 Bytes

README.md

File metadata and controls

26 lines (17 loc) · 689 Bytes

use-combined-state

Motivation

Restore how setState is used before React without hooks. Hooks is awesome. However setState should be passed full state as value returned in Redux reducer. You may also find grouping state under a single "namespace" improve readability.

Usage

import useCombinedState from 'use-combined-state';

// ...

const [ state, setState ] = useCombinedState({ visible: true, data: { titi: 'toto' } });


// set partial state to update, preserve `data` field.
setState({
  visible: false,
})

setState((prevState) => ({
  visible: !prevState.visible, // can pass a function which sets partial state
}))

<SomeComponent visible={state.visible}>