0

I put the Backdrop directly in the component and it all works, but in order to reuse it (and given the nature of react) I created a custom hook with the Backdrop. I encountered the problem that passing the same value as before (in this case, isLoading), it is always set as opened, for some reason I don't undertand. This is the hook I created:

import {CircularProgress,Backdrop} from '@mui/material';
import { useEffect, useState } from 'react';
export default function MyLoad(isLoading){
    const [loading,setLoading] = useState(false);
    useEffect(()=>{
        setLoading(isLoading);
        console.log(loading); //returns false as expected
    },isLoading);
    return (
    <Backdrop
        sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1,paddingLeft:"250px"}}
        open={loading} //its behaviour is as "opened" even loading is false
    >
        <CircularProgress color="primary" />
    </Backdrop>
    );
}

While in the parent component, as simple as:

<MyLoad isLoading={isLoading}/>

In fact as stated, I also used the intermediate value const [loading,setLoading] = useState(false); that I believe is not necessary ir order to discard any problem I may not be aware of, but the result is the same.

Germán
  • 1,007
  • 1
  • 7
  • 20

1 Answers1

0

It seems I have to use export default function MyLoad({isLoading}) with brackets to use the specific props.

Germán
  • 1,007
  • 1
  • 7
  • 20