1.0.2 • Published 10 months ago

zustand-create-state v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Zustand Create State

Create zustand state easily

When you need a state for a simple usage and dont want to write classic stuff for a simple getter and setter, this package is best for that scenario.

Usage

// /path/to/export/store .ts or .js

import createState from "zustand-create-state";

export const { useUserStore } = createState(false, "user");

And import it as you do for any hooks.

// /path/to/component or custom hook

import { useUserStore } from "path/to/export/store";

const Component = () => {
  const { user, setUser } = useUserStore(); // user and setUser auto generated

  return (
    <div>
      <span>{user ? "Logged In" : "Log In"}</span>
      <button
        onClick={() => {
          setUser(true);
        }}
      >
        Click to login
      </button>
    </div>
  );
};

Functions

createState()

Arguments

createState(defaultValue: any, stateName: string)

paramtype
defaultValueany
stateNamestring

Note

all storename and state getter with setter generated based on stateName.

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago