0.0.5 • Published 3 years ago

@barelyhuman/set-state-hook v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Install

$ npm install @barelyhuman/set-state-hook
# or
$ yarn add @barelyhuman/set-state-hook

Usage

import { useSetState } from "@barelyhuman/set-state-hook";

function Component() {
  const [state, setState] = useSetState({
    name: "Reaper",
    age: 16,
  });

  React.useEffect(() => {
    setState({
      name: "Hello World",
    });
  }, [setState]);

  // or

  React.useEffect(() => {
    setState((prevState, draftState) => {
      draftState.name = "Hello World";
      return draftState;
    });
  }, [setState]);

  return (
    <>
      <p>name: {state.name}</p>
      <p>age: {state.age}</p>
    </>
  );
}

Features

  • Easier state management for dependent state fields
  • Handle complex state updates using functional state handlers while keeping the simplicity of mutable objects
  • Tree Shakable
  • Small, 1.1kb GZipped

License

MIT © Reaper

0.0.5

3 years ago

0.0.4

3 years ago

0.0.4-3

3 years ago

0.0.4-2

3 years ago

0.0.4-0

3 years ago

0.0.4-1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago