I read this Reactjs async rendering of components and tried it to my own code but, error :
Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
I have no clue why it doesn't work. please help me!
constructor(props) {
super(props);
this.state = { asyncComponent: null };
}
public componentDidMount() {
import(`../../i18n/locales/${this.props.lang}`).then(o => {
this.setState({
asyncComponent: (
<CustomSelects
options={o.option}
formattedMessageId="createroom_genre"
value={this.props.genre}
handleValueChange={this.handleGenreChange}
/>
)
});
});
}
public render() {
return (
//...
{this.state.asyncComponent ? (
this.state.asyncComponent
) : (
<div />
)}
//...
)
}