How to trigger child re-rendering in React.js?

Sometimes, we want to trigger child re-rendering in React.js.

In this article, we’ll look at how to trigger child re-rendering in React.js.

How to trigger child re-rendering in React.js?

To trigger child re-rendering in React.js, we set the key prop to a new value.

For instance, we write

<ChildComponent key={updatedKey} />;

to set the key prop of ChildComponent to the updatedKey state or prop.

When updatedKey‘s value changes, ChildComponent will be re-rendered.

Conclusion

To trigger child re-rendering in React.js, we set the key prop to a new value.