0

In my project I have a call to an action that makes a webservice call and in turn dispatch actions to the result of the ws, these actions edit the store. My problem is in :

ComponentDidUpdate () {
    If (this.props.messages.length) {
      Const items = this.props.messages.filter (this.isDisplayable);
      This.timer = setInterval (() => {
        If (items.length> 0) {
          This.props.popItem (items);
        } Else {
          ClearInterval (this.timer);
        }
      }, This.props.interval);
    }
  }

In fact it is launched several times and I have warnings of

Warning: flattenChildren (...): Encountered two children with the same key, 1. Child keys must be unique; When two children share a key, only the first child will be used.

I used the componentDidMount but it launches it before api responds.

my question is: Is that there is a way to update the component only at the response of my action, or alternatively to pass the warnings ?

Hajji Tarik
  • 1,072
  • 7
  • 23
  • The same problem: [http://stackoverflow.com/questions/33391205/warning-flattenchildren-encountered-two-children](http://stackoverflow.com/questions/33391205/warning-flattenchildren-encountered-two-children) – Vitalii Andrusishyn Feb 01 '17 at 15:31
  • 1
    What language is this? In JavaScript keywords are case-sensitive and there are no `If` or `Const`. – Pavlo Feb 01 '17 at 15:31

3 Answers3

1

In my project I have a call to an action that makes a webservice call and in turn dispatch actions to the result of the ws, these actions edit the store.

None of the methods componentDidMount and componentDidUpdate are good. Observe the Store in Redux and update your component accordingly when the correct action TYPE is found.

Since you are using the Redux architecture, the state for all your components is in a single place — in the Store.


yes i know, but the problem is that componentDidUpdate is called several times which gives me the index error.

This is quite normal in React. Check this lifecycle.

enter image description here


What you should do is the govern the Redux architecture. I will try today to provide some diagrams for you. In general, anything you do will be from the global Store.

You may forget the React.Component state, and props you had in the non-Redux applications.

You typically need to use the Wrapper as a context provider around your app, where the context is the property of React.Component.

The context will be passed to all children and grandchildren so this will be the global Store organization.

Then you will need to read the Store from the context, and call the two typical methods: dispatch and subscribe.

enter image description here

prosti
  • 42,291
  • 14
  • 186
  • 151
1

try this :

componentWillReceiveProps(nextProps) {
    if (this.props.messages === nextProps.messages) return;
1

i had some probleme and i resolve it by force update

 forceUpdate () {
        If (this.props.messages.length) {
         ...
        }
      }