React - Display loading screen while DOM is rendering?

前端 未结 19 1681
我在风中等你
我在风中等你 2020-11-28 00:29

This is an example from Google Adsense application page. The loading screen displayed before the main page showed after.

I don\'t know how to do the same th

19条回答
  •  清酒与你
    2020-11-28 01:01

    The workaround for this is:

    In your render function do something like this:

    constructor() {
        this.state = { isLoading: true }
    }
    
    componentDidMount() {
        this.setState({isLoading: false})
    }
    
    render() {
        return(
            this.state.isLoading ? *showLoadingScreen* : *yourPage()*
        )
    }
    

    Initialize isLoading as true in the constructor and false on componentDidMount

提交回复
热议问题