Categories
React Answers

How to force remounting on React components?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *