0.0.12-beta.2 • Published 10 months ago

zustand-store v0.0.12-beta.2

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

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

0.0.12-beta.0

10 months ago

0.0.10

11 months ago

0.0.11

11 months ago

0.0.12-beta.2

10 months ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago