Answer the question
In order to leave comments, you need to log in
Is it possible to use Map in the state\stor?
The server returns an array of objects [{id:1, data:''}, {id:2, data:''}], which we put in the store\state.
What is good about an array is that we output it in a given order and do not worry. What is bad - if you need to fix an element - with a certain id - you first need to find it.
You can do it like this: data = [1,2]; dataList={'1': {data: ''}, '2': {data: ''},} It's so easy to display in order, there are no problems with editing data in the required id either. The downside is the conversion of the data sent by the server.
What if we use Map ( https://learn.javascript.ru/set-map) ?
new Map([
['1': data: ''], ['2': data: '']
]);
Answer the question
In order to leave comments, you need to log in
you have to find it first.
The redux documentation advises to cast the store to an object of the form { id1: { id:
'id1', ...someData }, id2: { id: 'id2', ...anotherData }, byIds: ['id1', 'id2'] } With this organization of the store, access to the properties is simple, the order is stored in an array, editing the store is easy.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question