首页 > 解决方案 > react-loading-skeleton 继续加载

问题描述

我是新来的反应并试图重做我的个人网站,我被困在这里试图使用 react-loading-skeleton。这是我的代码:

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

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

  render() {

    let button;

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

我希望在加载状态时加载文本

标签: reactjs

解决方案


我认为这会做你的工作:

 state={
        isLoading:true
    }

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

    }

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

推荐阅读