V
V
vaskadogana2017-02-20 18:45:17
React
vaskadogana, 2017-02-20 18:45:17

Why is the component not listening to the store?

Why is react not reacting after updating the repository?
the component is connected to the storage with the transport_list
3bbd08739f834557ad80c53ff3479a39.png
array - it is updated, but the update comes from the component of a direct connection with the current one that does not have one. (like the third level of nesting, I don’t want to drag it, I connected the redux)) I connect through the redux connect reacts only after events like onClick or onChange. I need it on the side. The only solution is how to subscribe Googled only subscribe, but again, how to call the component rerender is not clear. Everywhere examples from the series are hung on the input onChange and passed the event to the ancestor / descendant and called the rerender. Reacts to new information only after the events that I call according to the onChange / onClick scheme on

componentWillReceiveProps(nextProps){
    if(this.props.transport_list !== nextProps.transport_list){
      console.log('did update', this.props.transport_list)
    }
  }

does not react. Although through reactdevtools you can see that the value is new.
I can't overcome a week
Actually I'm interested in how to call a rerender.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vaskadogana, 2017-02-22
@vaskadogana

The problem was due to the fact that the name of the function (action) and the key matched.

F
Frozen Coder, 2017-02-20
@frozen_coder

Everywhere examples from the series are hung on the input onChange and passed the event to the ancestor / descendant and called the rerender.

Not a super specialist in react, but it seems like it should be done. You have a smart component that knows about the redux, in which there is a connection. He communicates with the store and takes from it what he needs in state and passes the required values ​​to descendants from his state down. It has stupid children that do not know about redux and can only call the onChange or onClick passed to them from the parent and consume the props passed by the parent. And in these functions, an action is called that makes a request to the server, then a new action arrives that the data has been received or an error has occurred. The corresponding Reducer responds to all these actions with changes in the store. Then the changes arrive as nextProps to the parent, where the parent's state is updated in componentWillReceiveProps . As a result, a recursive re-rendering of the parent and all its children with new props is triggered. Something like this.

M
Maxim, 2017-02-20
@maxfarseer

I will assume 2 situations:
1) As you have already been told in the comments, most likely you are "mutating" the array, and not returning a new one. For example, it doesn't suit you, the push method, to add an element and return a new array, use concat .
2) If you connected a component (using connect), and do not props down to the child, which in turn does not props to your component, which does not work and is at the 3rd level, not having a direct connection ... then it will not work must. You can use context to "not skip" , but you probably don't need it right now. So far, I have not had to use context directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question