react-universal-component icon indicating copy to clipboard operation
react-universal-component copied to clipboard

How to check that the component has loaded?

Open joetidee opened this issue 5 years ago • 0 comments

What is the best way to detect that the DoThis has loaded?

const DoThis = universal(import(/* webpackChunkName: 'do-this' */ 'src/do-this.js'));

class DoThisLoader extends React.Component {
    constructor() {
        super();
        this.state = {
            dataLoaded: false,
        };
    }    

    componentWillMount() {
        DoThis.preload();
    }

    componentDidMount() {
        loadSomeData().then(() => this.setState({ dataLoaded: true }));
    }

    render() {
        return dataLoaded && DoThis ? <DoThis /> : <DoThat />;
    }
}

joetidee avatar Jun 16 '20 08:06 joetidee