Reputation: 695
I am wondering how can i render a component conditionally without losing its space . Basically i want to remove the shift of the other components because of this div
Any suggestions ? Here is part of my code :
const [displayFeedbackMessage, setDisplayFeedbackMessage ] = useState();
useEffect(() => {
setDisplayFeedbackMessage(
<div>
{
displaySelectionResult &&
selected > 0 &&
<div>
{Pluralize("document", selected, true)}
{" "}selected out of{" "}
{Pluralize("document", available, true)}
{" "}available.
</div>
}
{
displayActionResult &&
<div>
{Pluralize("document", actioned, true)}
{" "} downloaded out of{" "}
{Pluralize("document", requested, true)}
{" "}requested.
</div>
}
</div>
)
},[selected, available, actioned, requested])
return (
<div>{displayFeedbackMessage}</div>
);
Upvotes: 3
Views: 1653
Reputation: 11
Visibilty for hiding the View and display "none" for hiding it without taking any space. I remember this is correct?
Upvotes: 0
Reputation: 1143
just add visibility
style to your div contain message, then set it visible : hidden
to show or hide it
style={{ height: '50px', visibility : condition ? 'visible' : 'hidden' }}
Upvotes: 3