useObjectState
Make it easier to work with state of objects
Documentation
npm install @clave/use-object-state
The goal of this hook is to make it easier to manipulate objects stored in state. There are methods available to set, edit or append/change several properties oy the object stored in state. The manipulation methods are available on the setState
method, for example setState.set('key', value)
.
Usage
import useObjectState from "@clave/use-object-state";
const [value, setValue] = useObjectState({
name: "Ada Lovelace",
born: "December 10, 1815",
died: "November 27, 1852",
aged: 36,
});
console.log(value);
setValue({});
setValue.set("name", "Grace Hopper");
setValue.with({
name: "Grace Hopper",
aged: 85,
});
setValue.edit("name", (name) => name.ToUpperCase());