0

I am trying to fetch data in the useEffect Hook of a view as the following code shows. If I just output the response.data obj, the output ist correctly shown, but if I output the editObj something complete different is shown.

const [editObj, setEditObj] = React.useState({});

const fetchObject = async () => {
     const response = await API.get('/block-management/kblock/'+id);
     setEditObj(response.data.data);
     console.log(response.data.data); 
     console.log(editObj);
}

useEffect(() => {
     fetchObject();
}, []);

useEffect(() => {
     console.log(editObj);
}, [editObj]);


return (
            <form onSubmit={handleSubmit}>
                <Grid container spacing={2}>
                    <Grid item xl={12}>
                        <BlockInputBasic object={editObj} />
                    </Grid>
                </Grid>
            </form>
);


first Output: { }
second Output: Object { :id: 12123, .... name: "test", ....}

Child:

export default function BlockInputBasic(props) {
    const classes = useStyles();


return (
   <Card className={classes.card} sx={{borderRadius: 5}}>       
       <TextField
            fullWidth
            label="Name"
            name="name"
            required
            variant="outlined"
            defaultValue={props.object.name}
       />
   </Card>
);

I appreaciate your help!

Regards

n3verm1nd
  • 13
  • 4

0 Answers0