Zukeeper icon indicating copy to clipboard operation
Zukeeper copied to clipboard

Not Working with Zustand 4.4.6

Open vaaiibhav opened this issue 2 years ago • 2 comments

import { create } from "zustand"; import zukeeper from 'zukeeper'; const useSecondGame = create(zukeeper(set) => ({ bears: 123454, increasePopulation: () => set((state) => ({ bears: state.bears + 1 })), removeAllBears: () => set({ bears: 0 }), })); window.store = useSecondGame; export { useSecondGame};

image

vaaiibhav avatar Jan 08 '24 07:01 vaaiibhav

Also Tried, yet still not working

import { create, useStore } from "zustand"; import zukeeper from 'zukeeper';

const useSecondGame = useStore(zukeeper(set) => ({ bears: 123454, increasePopulation: () => set((state) => ({ bears: state.bears + 1 })), removeAllBears: () => set({ bears: 0 }), })); window.store = useSecondGame; export { useSecondGame};

image

vaaiibhav avatar Jan 08 '24 07:01 vaaiibhav

Looks like you're not passing the right args into the zukeeper function @vaaiibhav, hence why VSCode is showing TSC errors about expected commas and semi-colons. You need to either move the closing parenthesis of the zukeeper() call to the end of the const declaration, or add another opening one around the set arg.

For example

const useSecondGame = useStore(zukeeper(set => ({
  bears: 123454,
  increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
  removeAllBears: () => set({ bears: 0 }),
})));

window.store = useSecondGame;

export { useSecondGame};

Not tested the above in an IDE or anything but it should be right

TomPlum avatar Sep 09 '24 12:09 TomPlum