use-combined-state
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i use-combined-state

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

3.54 kB

Total Files

5

Last publish

Collaborators

  • xc1427