Skip to main content
Version: Next

useSetState()

This hook gives you a setState function for a given state

Arguments#

statePath#

path of the nestable state to be selected

useSetState('todos.completed')

Returns()#

setState()#

setState(payload, setter?: (state, payload) => newState)

Example#

import { useEffect } from 'react'
import useReduxState, { useSetState } from 'use-redux-states'
const Component = () => {
useReduxState({
state: {
state1: 'a',
state2: 'b'
},
path: 'component_state'
})
const setState = useSetState('component_state')
useEffect(() => {
setState({ state2: 'c' }, (component_state, payload) => ({
...component_state,
...payload
}))
// component_state {state1: 'a', state2: 'c'}
}, [])
}