Skip to content

React hooks like useState but can set partial state

Notifications You must be signed in to change notification settings

xc1427/use-combined-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

React hooks like useState but can set partial state

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published