What are you trying to do? For normal React applications, you should just let React handle all that messy stuff. Your code example is how I would handle it, though I think the variables should be something like hasData and setHasData or whatever.
I think we are disagreeing about terminology here. I don’t “unmount” a component. I simply stop rendering it and let React unmount it as it sees fit.
What you are doing in the code is what I would call “conditional rendering”. As a professional React developer I have never used unmountComponentAtNode and having looked at it, I think that we should almost never need that.
In short, what you are doing with your code is a very common pattern. You can put ternary statements or && short circuits into your code, or you can do some kind of a return early pattern.
so normally people don’t really use “unmountComponentAtNode” to remove(unmount) a component?
That is correct. I’m a professional React developer and I’d forgotten that that actually exists.