简体   繁体   English

react-loading-skeleton持续加载

[英]react-loading-skeleton keeps on loading

I'm new to react and trying to redo my personal site, I'm stuck here trying to use react-loading-skeleton. 我是新来的反应者,试图重做我的个人站点,我被困在这里,试图使用react-loading-skeleton。 Here's my code: 这是我的代码:

  constructor() {
      super();
      this.state = { isLoading: true }
  }

  componentDidMount() {
      this.setState({ isLoading: false })
  }

  render() {

    let button;

    if (this.state.isLoading) {
      button = 'Hi, there!';
    } else {
      button = <Skeleton />;
    }

I want the text to load when the state is loaded 我希望文本在加载状态时加载

I think this will do your job: 我认为这可以完成您的工作:

 state={
        isLoading:true
    }

    componentDidMount(){
        setInterval(() => {
            this.setState({isLoading:false})
        }, 1000);

    }

    render() {
        return (
            this.state.isLoading?(
                <div>Loading...</div>
            ):(
                <div>
                    Welcome
                </div>
            )
        )
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM