Socket
Socket
Sign inDemoInstall

zustand-immer-store

Package Overview
Dependencies
9
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    zustand-immer-store

A ~268B library to create type-safe redux-style stores with Zustand and Immer


Version published
Weekly downloads
25
increased by8.7%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Zustand Immer Store

npm npm bundle size

A ~268B library to create type-safe redux-style stores with Zustand and Immer

Live demo on codesandbox

Installation

yarn add zustand-immer-store

Usage

// counter-store.ts
import { createStore } from "zustand-immer-store";

const useCounterStore = createStore(
  { counter: 0 },
  {
    createActions: (set) => ({
      increment: () =>
        set((draft) => {
          draft.state.counter++;
        }),
      decrement: () =>
        set((draft) => {
          draft.state.counter--;
        }),
    }),
  }
);

export default useCounterStore;
// App.tsx
import useCounterStore from "./counter-store";

export default function App() {
  const { state, actions } = useCounterStore();
  return (
    <main>
      <div>
        <button onClick={actions.decrement}> - </button>
        <div>{state.count}</div>
        <button onClick={actions.increment}> + </button>
      </div>
    </main>
  );
}

Keywords

FAQs

Last updated on 21 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc