Parris February 2016

If a component is "unmounted" will it ever again be used?

In react if a component is unmounted will that object ever again be reused?

Use case: let's say that component is sometime's shown from a higher level in an if statement.

If that component disappears a due to a state change then componentWillUnmount call will fire of course. When it later re-appears due to a state change, does react reuse this same component or does it create it from scratch? I would guess there is no guarantee of a new component, which is why both WillMount and WillUnmount exist.

Answers


Nathan Hagen February 2016

No, once it is unmounted, the instance will be garbage collected if there are no references, and separately, if a component is re-mounted, there will be a new instance.

https://github.com/facebook/react/issues/4770#issuecomment-136928760

Post Status

Asked in February 2016
Viewed 3,252 times
Voted 6
Answered 1 times

Search




Leave an answer