knocklabs / javascript

Official JavaScript packages for interacting with Knock
https://knock.app/
MIT License
14 stars 3 forks source link

Zustand version #102

Open DavoCg opened 6 months ago

DavoCg commented 6 months ago

Hello,

This package is using an old zustand version and this message [DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use import { useStore } from 'zustand'.

Would you consider upgrading to last zustand version and using import { createStore } from "zustand" instead of import create from "zustand/vanilla";

Instead of

export default function createStore() {
  return create<FeedStoreState>((set) => ({

It would like

export default function createFeedStore() {
  return createStore<FeedStoreState>()((set) => ({

I consumer land it would be used like:

import { useStore } from "zustand";

const count = useStore(feed.store, (state) => state.metadata.unseen_count);

This modification would require some changes in feed code,

Happy to submit a PR if you consider it and don't hesitate to tell me if i miss something

mohammadzeyghami commented 6 months ago

hey test this syntax

import { create } from "zustand";

interface CounterStore { count: number | string; setCount: (item: string | number) => void; } export const useCounterStore = create((set) => ({ count: 0, setCount: (item) => { set({ count: item }); }, }));

in your component const { count , setCount } = useCounterStore();