I've been browsing a lot of stack overflow questions about this subject, but I still don't get it... I'm trying this solution answering my problem very well : https://stackoverflow.com/a/42601915/2617419
Here is what I have :
class EnterpriseContainer extends Component {
constructor(props) {
super(props);
this.state = {hit: props.hit};
}
async componentDidMount() {
if (this.state.hit === undefined) {
let h = await getObjectIDAsync();
this.setState({hit: h});
} else {
}
}
render() {
return (
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<Paper className="paper" elevation={1} style={{'paddingLeft': '0px'}}>
<Grid
container
>
<EnterpriseLogo image={this.state.hit.image}/>
<EnterpriseInfo hit={this.state.hit}/>
</Grid>
</Paper>
</Grid>
);
}
}
I understand that this logic is made to first load the react components, and then asynchronisly load data into it.
If I simply load the hit object as a stringify object (using JSON.stringify(hit)
) into my component, it works fine.
But the components EnterpriseLogo
and EnterpriseInfo
use the hit
props referencing for example props.hit.objectID
, and it will make the app crash because this ref doesn't exist yet.
I think I have a design problem somewhere but I'm not sure where to go.