SolidJSS
SolidJSโ€ข4y agoโ€ข
4 replies
Raqueebuddin Aziz

How to update nested store values such that it triggers updates

I have a store with the shape IUserState. Now I want to update some projectGroup to add a new project to it. How can I achieve this so that updates are triggered?

export interface IUserState {
  projectGroups: IProjectGroup[];
}

export interface IProjectGroup {
  name: string;
  projects: IProject[];
}

export type IProject =
  | {
      name: string;
      description: string;
      logs: IActivityLog[];
    } & Xor<
      { paid: true; hourlyRate: number; currency: string },
      { paid: false }
    >;


I tried this, it does update the store but doesn't trigger updates.

setUserState(
  "projectGroups",
  produce((projectGroups) => {
    projectGroups[groupIndex].projects = [
      ...projectGroups[groupIndex].projects,
      (formData.paid
        ? {
            name: formData.name,
            description: "",
            paid: true,
            logs: [],
            hourlyRate: formData.hourlyRate,
            currency: formData.currency,
          }
        : {
            name: formData.name,
            description: "",
            logs: [],
            paid: false,
          }) as IProject,
    ];
  })
);


Thanks for any assitance ๐Ÿ™‚
Was this page helpful?