我有一个非常简单的React.js
组件,我需要做一个isomorphic
(呈现在服务器上)。问题是有帮助的信息后,才ajax
请求完成,这样渲染该组件:react.js不渲染,直到ajax请求完成
export default React.createClass({
getInitialState() {
return {}
},
componentDidMount() {
fetch("https://stackoverflow.com/users/").then(response => {
this.setState(users: response.data)
})
},
render() {
if (this.state.users == undefined) {
return <div />
}
return <div>{this.state.users.map(some_function)}</div>
}
})
的问题是,这是毫无意义空车返回div
搜索引擎。我想要ajax
请求完成(即使在服务器上)并仅在此之后呈现。我怎样才能做到这一点?
我相信你想采取父组件,并使用道具而不是状态,让父组件决定是否渲染它。 – Dencker
@Dencker您能解释一下如何决定是否渲染它吗? – asiniy