react-setters-state
v0.8.7
Published
Convert your state to setters.
Downloads
14
Readme
react-setters-state
Convert your state to setters.
Usage
Basic Usage
import useSettersState from "react-setters-state";
export function Example() {
const stateWithSetters = useSettersState({
age: 1,
});
}
With a custom updater
import { useState } from "react";
import useSettersState from "react-setters-state";
export function Example() {
const [state, setState] = useState({
age: 1,
});
const stateWithSetters = useSettersState(state, setState);
}
API
useSettersState(state, updater, setterKeyPrefix)
| parameter | required | type | description |
| --------------- | -------- | -------------------------------------- | ----------------------------------------------------------------------------------------- |
| state | true | object | input state. |
| updater | false | (cb: (prev: TState) => TState) => void | a higher order function like setState
that will receive a cb
function to update state |
| setterKeyPrefix | false | string | the method prefix string of setters, default to "set"
|