React › Virtual DOM & Reconciliation
How does React's reconciliation process handle components of a completely different type appearing in the same position?
IntermediateAnswer
When React compares the new virtual DOM to the old one and finds a completely different type of element or component in the same position, such as a div being replaced by a span, it assumes these are unrelated and simply removes the old one entirely, along with any of its state, before creating and inserting the new one fresh.
// Before: <LoggedOutView />
// After: <LoggedInView />
// React completely removes LoggedOutView, including any of its internal state,
// and creates LoggedInView fresh, since they are considered entirely different componentsReal-world example A login page's form component is fully unmounted and a completely separate dashboard component is mounted fresh the moment a user successfully logs in, since React treats these as entirely unrelated components rather than trying to update one into the other.