Answer the question
In order to leave comments, you need to log in
What is the correct way to work with a large Redux structure?
Good afternoon. There is such a question.
An application is being developed using Redux, React
The data is updated in the state via a socket, once a second. This is a large list of data, such as the following structure:
var items = [
{
id :1,
name: "test_item",
country: {
id: "1",
name: "country_name_1"
},
tournament: {
id: "1",
name: "tournament_name_1"
}
},
{
id :2,
name: "test_item2",
country: {
id: "2",
name: "country_name_2"
},
tournament: {
id: "1",
name: "tournament_name_2"
}
},
{
id :3,
name: "test_item3",
country: {
id: "1",
name: "country_name_1"
},
tournament: {
id: "1",
name: "tournament_name_1"
}
},
{
id: 4
},
{
id: 5
}
]
var formatted = {
countries: {
1: {
id: "1",
name: "country_name_1",
tournaments: {
1: {
id: 1,
name: "tournament_1",
items: {
1: {
id: 1,
name: "test_item",
},
2: {
id: 1,
name: "test_item",
},
}
},
2: {
id: 3,
name: "tournament_3",
items: {
3: {
id: 3,
name: "test_item_3",
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
A connection is opened in the desired container.
When data is received, dispatch is done.
The reducer is processing - just create a separate action to process such a batch of data.
But here a problem can arise - an idle update, because mapStateToProps is called after each dispatch, regardless of which part of the application was updated. An object is changed by reference - a blank render is started (PureComponent aka pure-render-mixin helps, but it still does extra work).
Wrap heavy mapStateToProps with the reselect library .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question