Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React 16 : componentDidUpdate Warning: Scheduled a cascading update

I profiled the performance of my application using react redux by following this article by Ben Schwarz.

In the user timing section, i get these warnings (with a no entry sign):

enter image description here

There is two messages:

  • (Committing Changes) Warning: Lifecycle hook scheduled a cascading update
  • Connect(MyComponent).componentDidUpdate Warning: Scheduled a cascading update

I made some search but i found nothing special. It seems related to the componentDidUpdate function of the connect HOC of react-redux.

What does these messages means ?

like image 421
gontard Avatar asked Dec 01 '17 18:12

gontard


People also ask

Can I update state in componentDidUpdate?

The componentDidUpdate is a part of a React component life cycle. We use it to react to external changes in component's props or internal state changes. With the componentDidUpdate you can modify the underlying DOM nodes, request remote data, and update the internal state of your component.

Is componentDidUpdate called after setState?

You may call setState() immediately in componentDidUpdate() but note that it must be wrapped in a condition like in the example above, or you'll cause an infinite loop. It would also cause an extra re-rendering which, while not visible to the user, can affect the component performance.

How do I render after componentDidUpdate?

The componentDidUpdate method is called after the render method of the component is done executing. That means that it will be called after all children's render methods have finished. This is implied in the documentation you linked: Use this as an opportunity to operate on the DOM when the component has been updated.

How can componentDidUpdate be used in class component?

The componentDidUpdate()is called after componentDidMount() and can be useful to perform some action when the state of the component changes. Parameters: Following are the parameter used in this function: prevProps: Previous props passed to the component. prevState: Previous state of the component.


1 Answers

The messages mean that componentDidUpdate is getting changed props or setting the state and so the update will cascade (happen right after the last update) because it is the last lifecycle method called during an update. Basically React has determined that another update needs to happen and it isn't even finished with it's current update yet. I'm not sure if this is a problem with react-redux or your application.

like image 103
Dakota Avatar answered Sep 30 '22 01:09

Dakota