Socket
Socket
Sign inDemoInstall

zustand-store

Package Overview
Dependencies
6
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand-store

zustand store


Version published
Maintainers
1
0

Weekly downloads

Readme

Source

zustand-store

NPM JavaScript Style Guide

A zustand store with immer, which makes zustand support class pattern.

Install

npm install --save zustand-store

Usage

import React from 'react';
import { useStore } from './store';

const App = () => {
  const store = useStore();
  const onClick = () => {
    store.updateTime(Date.now());
  };
  const isLoading = store.loading.updateTime;

  return (
    <div>
      <div>current time: {isLoading ? 'loading...' : store.time} 😄"</div>
      <button onClick={onClick}>click me</button>
    </div>
  );
};

export default App;

./store.tsx

import Store from 'zustand-store';

class StoreClass extends Store.BaseStore<StoreClass> {
  public time = Date.now();

  @Store.loading()
  public async updateTime(time: number) {
    return new Promise<void>((resolve) => {
      setTimeout(() => {
        this.set((state) => {
          state.time = time;
        });
        resolve();
      }, 2000);
    });
  }
}
export const useStore = Store.create(StoreClass);

License

MIT © JJVvV

FAQs

Last updated on 07 Aug 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