Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MUI Fade component does not show, hide, or fade components

I switched child components from conditional rendering to being wrapped by <Fade /> but Fade doesn't work at all, both components always display. Here is the current code:

// inside top level component
{/*{adminView === bodyViews.addNewCoupon &&*/}
<Fade
  in={Boolean(adminView === bodyViews.addNewCoupon)}
  timeout={2000}
>
  <AddCouponForm />
</Fade>
{/*}*/}
  
{/*{adminView === bodyViews.viewCurrentCoupons &&*/}
<Fade
  in={Boolean(adminView === bodyViews.viewCurrentCoupons)}
  timeout={2000}
>
  <ViewCoupons />
</Fade>
{/*}*/}

Based on the API here. I believe in set to true should cause the component to fade in. This worked for causing a conditional render in the commented out unary but does not seem to work within the in value. What mistake is being made?

Update

When I comment the custom components and inserting something like <p>Section 1/2</p> then the fade works. Something about the custom compoonents must cause the fade not to work

like image 476
Sean D Avatar asked Jul 17 '19 14:07

Sean D


People also ask

What is fade in MUI?

The Fade transition is used by the Modal component. It uses react-transition-group internally.

What is Fade in react?

Fade Component adds a fade animation to a child element or component. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Fade Component in ReactJS using the following approach.


1 Answers

The issue was traced specifically back to Custom components: they don't seem to work as direct children of <Fade />. Issue is solved by wrapping the custom component children in a div.

  <Fade
    in={ Boolean(adminView === bodyViews.addNewCoupon) }
    timeout={ 4000 }
  >
    <div>
      <AddCouponForm />
    </div>
  </Fade>     

  <Fade
    in={ Boolean(adminView === bodyViews.viewCurrentCoupons) }
    timeout={ 4000 }
  >
    <div>
      <p>Section 2</p>
      <ViewCoupons />
    </div>
  </Fade>

As a side note, Fade also seems to have issues with more than one child. Therefore all children should go inside a single div element.

like image 150
Sean D Avatar answered Dec 14 '22 22:12

Sean D