export function useObjectState<S>(initial: S): ObjectState<S>
Accepts a state object.
Returns the object { state, set<Key> }.
{ state, set<Key> }
Has a superficial comparison of objects.
import { afc, useObjectState } from 'react-afc' function Component(props) { const { state, setName, setAge } = useObjectState({ name: 'Boris', age: 30 }) function changeAge() { setAge(20) } return () => <> <p>Name: {state.name}</p> <p>Age: {state.age}</p> <button onClick={changeAge}> Change age </button> </> } export default afc(Component)
There was an error while loading. Please reload this page.
Component
Lifecycle
State
Redux
Other