I have in my reducer for a store, need to update an inner array object value:
for:
export interface SiteState {
site: Site;
}
and
export interface Site {
id: number | null;
uuid: string;
subscriptions?: (SubscriptionI)[] | null;
}
and would like update the site->subscriptions[x] = action.payload
// edited with solution
function handle(state: SiteState, action: Successaction): SiteState {
const sub = state.site.subscriptions.map( subs => {
if (subs.uuid === action.payload.uuid) {
return action.payload
} else {
return subs;
}
});
const site = { site: {...state.site, subscriptions: sub} };
return site
}
I tried the spread operator but he just push my new subscriptions into the root site, si don"t know how write it for update the object SubscriptionI who is an array.