Sometimes, we want to force remounting on React components.
In this article, we’ll look at how to force remounting on React components.
How to force remounting on React components?
To force remounting on React components, we can set the key prop of the component to a new value.
For instance, we if we change
<Component key="1" />
to
<Component key="2" />
then the Component component will be remounted since key changed from 1 to 2.
Conclusion
To force remounting on React components, we can set the key prop of the component to a new value.