0
不知道我在做什麼錯,但我的組件包裹的setTimeout沒有被呈現給DOM:麻煩組件中的setTimeout來渲染
const ContentMain = Component({
getInitialState() {
return {rendered: false};
},
componentDidMount() {
this.setState({rendered: true});
},
render(){
var company = this.props.company;
return (
<div id="ft-content">
{this.state.rendered && setTimeout(() => <Content company={company}/>,3000)}
</div>
)
}
})
試過了,它不起作用。目錄會在屏幕上顯示。然後過了一段時間(3000年),它做了一些事情。所以它不會延遲渲染,因爲componentDidMount在渲染後運行 – PositiveGuy
初始渲染應該不返回任何內容(因爲this.state.rendered爲false),並且在componentDidMount之後3秒渲染將被設置爲true,這會觸發另一個渲染,新的渲染。如果某些東西不能正常工作,那可能是別的東西了......有什麼錯誤? –
是的,我沒有看到延遲發生,沒有錯誤。 – PositiveGuy