I'm using the Fade component of Material UI as part of a stepper. I want the steps to fade in on render. How can I make it work? sandbox
function getStepContent(step) {
switch (step) {
case 0:
return (
<Fade in>
<div>'Step 1: Select campaign settings...'</div>
</Fade>
);
case 1: ...
default:
return "Unknown step";
}
}
You could make a separate component for the Fade components, that would begin with the in prop set to false and then immediately set it to true using some state and a useEffect:
function CustomFade(props) {
const [show, setShow] = useState(false);
useEffect(() => {
setShow(true);
}, []);
return <Fade in={show}>{props.children}</Fade>;
}
Also, you have to add the key prop to the CustomFade, so React remounts it.
function getStepContent(step) {
switch (step) {
case 0:
return (
<CustomFade key="step0">
<div>'Step 1: Select campaign settings...'</div>
</CustomFade>
);
case 1: ...
default:
return "Unknown step";
}
}
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