Sorry, I'm not following. Can you give an example of a scenario where you need to force a rerender of children by unmounting them?
Can you use the context API instead or forceUpdate() which actually skips shouldComponentUpdate?
Ideally, every component should be rerendered only if there are changes to the DOM. In this case, since it is a contrived example, I can't wrap my head around a practical use-case. Thanks.
Agreed, good point Nick. This should be used as a last resort or in special cases.
In my case, we needed to reload the entire page due to a change in where the API lives. Data can come from either a 'global' or 'local' source, and the user has the ability to switch between the two. Most of our API calls live in componentDidMount(), so there is no easy way of re-sending all the page's API calls without a rerender. Something like Redux could of helped, but would cause a huge rewrite.
Sorry, I'm not following. Can you give an example of a scenario where you need to force a rerender of children by unmounting them?
Can you use the context API instead or forceUpdate() which actually skips shouldComponentUpdate?
Ideally, every component should be rerendered only if there are changes to the DOM. In this case, since it is a contrived example, I can't wrap my head around a practical use-case. Thanks.
Agreed, good point Nick. This should be used as a last resort or in special cases.
In my case, we needed to reload the entire page due to a change in where the API lives. Data can come from either a 'global' or 'local' source, and the user has the ability to switch between the two. Most of our API calls live in
componentDidMount()
, so there is no easy way of re-sending all the page's API calls without a rerender. Something like Redux could of helped, but would cause a huge rewrite.Practical usage: reactjs.org/blog/2018/06/07/you-pr...
I remember reading that, but never needed to use it so probably forgot about it. However, that use-case makes sense.
I generally usee getDerivedStateFromProps because it helps keep the components more efficient.