Answer the question
In order to leave comments, you need to log in
What is the best way to store data in a store?
The question arose, when storing a list of records in a store, in what form is it better and more convenient to store data ... in an array or in an object?
So:
[
{
id: "Ad6dcCD3",
name: "Hello",
age: "55"
},
{
id: "SdQcC37a",
name: "Lol",
age: "55"
},
]
{
Ad6dcCD3: {
id: "Ad6dcCD3",
name: "Hello",
age: "55"
},
SdQcC37a: {
id: "SdQcC37a",
name: "Hello",
age: "55"
}
}
Answer the question
In order to leave comments, you need to log in
Good afternoon! Your question is covered very well in the second course on egghead from the creator of Redux. Concretely, one of the closest answers to your question is https://egghead.io/lessons/javascript-redux-normal... (using normalizr).
But my answer is not so much in the video about the "normalizer", but about the fact that you watch the whole course and you will get acquainted with such a topic as selectors. That is, you will pull out only the necessary data in the components using certain selector functions that you will describe in your reducers. You will be able to use combineReducers at least 1 level deeper in order to hold:
a) an array of id-niks
b) an object with keys, in the form of id of your records ( object of objects , so to speak)
I say this based on my experience. After switching to "array with id" + "object of objects" + selectors => the problem mentioned in the question disappears!
Here is a screenshot from the project I am currently working on: (a list of suppliers is rendered on the page)
PS This issue will be discussed in detail in a new tutorial, but I'm afraid it will not be released until the end of summer.
Maxim, you have a question.
But what if data like yours needs to be converted for rendering?
Those. the Products array comes to you, each conditionally has a bunch of parameters and a Provider parameter:
{
"name": "n",
"id": "i",
"provider": "p",
"sub_provider": "sp"
}
var products_structure = {
"provider_1": {
"name": "",
"id": "",
"sub_providers": {
1: {
"name" :"",
"id" :"",
"products": {
1: {},
2: {}
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question