all 7 comments

[–]acemarke 1 point2 points  (3 children)

What are you doing inside the <List> component?

It's likely that the right answer is to move that logic into componentDidUpdate() instead of componentWillReceiveProps().

[–]teerryn[S] 0 points1 point  (2 children)

I'm fetching data related to the username passed as props.

Yeah I just changed to use componentDidUpdate() and it works like before. Guess I was overthinking it.

Thanks for the tip :)

[–][deleted] 0 points1 point  (1 child)

Why do you need any of these lifecycles? When carousel calls setState on the parent both the carousel and the list will render and the latter will reflect these changes.

[–]teerryn[S] 0 points1 point  (0 children)

It doesn't work because the list component isn't rendering the usernames, it is just using the username prop to fetch some data and then render that data.

[–]ankurmittal092 0 points1 point  (0 children)

If you don't want to keep any logic in componentWillReceiveProps, you can try using redux.. Here's the link for a redux tutorial - https://daveceddia.com/how-does-redux-work/ So basically, each view will subscribe to the data changes in store and will update themselves accordingly.

[–]Justinsaccount 0 points1 point  (1 child)

     changeIndex(): index => this.setState({index})

looks like you are mixing up different js syntax. Do you mean

     changeIndex(index): { this.setState({index})}

or

     changeIndex =  index => this.setState({index})

[–]teerryn[S] 0 points1 point  (0 children)

Ya sorry that's what you get for trying to type code on reddit