T
T
toly192017-06-10 19:45:54
JavaScript
toly19, 2017-06-10 19:45:54

Why is react+redux parent updated?

There are 2 components:
App and AppSmall
AppSmall is nested in App
and App and AppSmall are connected to the store via connect.
Now if I call dispatch on the nested AppSmall, it re-renders along with the parent.
Why.
Maybe that's how it should be???
I need that, as with setState, only the component + (if necessary) descendants are re-rendered.
There is a lot of code, so here it is: codepen.io
PS open the console

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-06-10
@toly19

...
let AppSmallRedux = connect(
    (store) => ({ data: store.reducerAppSmall }), // (1)
    dispatch => ({
        update: () => dispatch({ type: "UPDATE_AppSmall" })
    })
)(AppSmall);
...
let AppRedux = connect(
    (store) => ({ data: store.reducerApp }), // (2)
    dispatch => ({
        update: () => dispatch({ type: "UPDATE_App" })
    })
)(App);
...

In paragraphs (1) and (2) you subscribed to the entire STORE, therefore, if it changed, then all the "connected" components reacted to it. If you subscribe only to the "necessary piece of the store" - then everything will be ok.
Your updated example (codepen).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question