2

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 enter image description here

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>

    );
PandaMastr
  • 687
  • 3
  • 14
  • 35

2 Answers2

2

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' }}
Anh Tuan
  • 1,113
  • 5
  • 12
2

You could use the styles visibility (hidden or visible) or opacity (0 or 1). They are a bit different as you can read here.

Wannes
  • 1,019
  • 2
  • 11
  • 18