Giter VIP home page Giter VIP logo

zustand-store-addons's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zustand-store-addons's Issues

Simpler fetch [discussion]

first, great library. very interesting stuff - been looking for computed since vuex :)
regarding something i saw in the docs:

const [count, increment, doubleCount, total] = useStore(
    'count, increment, doubleCount, total'
  )

you've made variables as a one long string... than said "This is looking good!" but that method is prone to user errors. most new projects are typescript these days and that is considered breaking the rules.

Typescript types of `create` don't match Zustand.

The following code (not a special case) does not work with import create from "zustand-store-addons"; but works with import create from "zustand"; :

import create from "zustand-store-addons";

export type AppStore = {
  isOpen: boolean;
  setIsOpen: (isOpen: boolean) => void;
};

export const useLabellingStore = create<AppStore>(
  (set) => ({
    isOpen: false,
    setIsOpen: (isOpen: boolean) => set({ isOpen }),
  })
);

I get this error, because zustand-store-addons wants the set function to be called with something of type PartialState<AppStore, keyof AppStore> which reduces to Pick<AppStore, keyof AppStore>.

Screenshot 2021-06-21 at 09 23 58

While zustand wants the set function to be called with something of type PartialState<AppStore, "isOpen">

Screenshot 2021-06-21 at 09 30 07

Watchers vs Computed [Question]

What are the strict differences / when should I use which?
Can watchers be made to watch two specific states?
Is computed just re-run when ANY of the states change?

Thanks!

Defining Create with Typescript

First of all, thanks for creating this repo! I'm trying it out now.

I was wondering, how do you define "set" in typescript when creating the store? My original Zustand code used to look like this:

const useRoomState = create((set: SetState, get: GetState) => ({
...

But 'SetState' is not assignable with Zustand-addon's new create function. Any suggestions for what type to define set as?

Type error when using immer middleware

Example code:

import create from "zustand-store-addons";

interface Store {
    value: number;
    increase: () => void;
}

export const useStore = create<Store>(
    (set, get) => ({
        value: 0,

        increase: () => {
            set(state => { // Report error at this line
                ^^^^^^^^^^
                state.value++;
            });
        },
    }),
    { middleware: [immer] },
);

Error info:

Argument of type '(state: Store) => void' is not assignable to parameter of type 'PartialState<Store>'.
  Type '(state: Store) => void' is not assignable to type '(state: Store) => Partial<Store>'.
    Type 'void' is not assignable to type 'Partial<Store>'.ts(2345)

It looks like the original action type is not compatible with the action type after using Immer middleware.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.