Is it necessary to have ids in ngrx/entities that will not be changed? I want to use string property path
as id. It is uniq. But it can be changed. Should I use uuid as ids in this case?
You can pass in a function to override the default id selection when creating your adapter:
export const adapter: EntityAdapter<Model> = createEntityAdapter({
selectId: (model: Model) => model.modelId,
});
We needed to update the Ids in the EntityAdapter because the API returns the unique ID, for future references, which is not available when first adding it to the store. So you could change it yourself if you want to.
const updateSelectedRooms = new selectedRoomsActions.UpdateSelectedRooms(
{
entities: [
{
changes: {
id: mockResponse.data.rooms[0].roomId,
pricing: mockResponse.data.rooms[0].pricing,
},
id: '1234-5678',
},
],
},
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With