Say you are passing a prop called show
to a component. If the prop value is true, you should render the full component normally. If it is false, you should not display anything.
You can do this two ways.
display: none
attribute to the component's DOM element. Which ones is the correct or the preferred way?
I do not think there will be any definite answer for this question. Each approach has its benefits and drawbacks.
With CSS you have:
With returning null
:
From my point of view the decision will be based upon the structure of your control. If it have complex structure with many nested children and you do not have any means of restoring their states when switched on again - go with CSS, but I would say this is a short term solution for quite simple controls only. In all other cases I would go with not rendering a component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With