Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant user Array of Map type to store data #2381

Closed
saketverma-03 opened this issue Mar 2, 2024 · 0 comments
Closed

Cant user Array of Map type to store data #2381

saketverma-03 opened this issue Mar 2, 2024 · 0 comments

Comments

@saketverma-03
Copy link

import { Collection, CollectionItem, ContainerNode } from "./types";
import { create } from "zustand";

import { devtools } from "zustand/middleware";

type State = {
  collection: Collection;
  user: string;
};

type Actions = {
  addContainerNode: () => void;
  removeContainerNode: (idx: number) => void;
};

const n = new Map<string, ContainerNode>();
n.set("lol", {
  title: "new",
  content: "new",
});
const initialCollection = [n];

export const useCollectionStore = create<State & Actions>()(
  devtools((set) => ({
    user: "dasked",
    collection: initialCollection,
    addContainerNode: () =>
      set((state) => {
        const temp = [...state.collection, n];
        return { ...state, collection: temp };
      }),

    removeContainerNode: (idx) =>
      set((s) => {
        const temp = s.collection.filter((_, i) => i != idx);
        return { ...s, collection: temp };
      }),
  })),
);

the collection is empty object in state , but it should be some sort of map !
i'm not sure how to get the behavior i want
image

i want to store array of Map in my collection in store.

@pmndrs pmndrs locked and limited conversation to collaborators Mar 2, 2024
@dai-shi dai-shi converted this issue into discussion #2382 Mar 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant