【发布时间】:2016-10-21 01:21:10
【问题描述】:
我正在查看https://facebook.github.io/react/docs/component-specs.html 此处的文档,但不知道为什么会出现此问题。
我的情况是我有一个像
这样的组件export default class MyComponent extends Component
{
constructor(props)
{
super(props);
this.state = { something: null };
}
render()
{
// ... uses something
}
ProductSorter.propTypes =
{
something: PropTypes.string.isRequired
}
我的render 函数当然假设something 不是null,因为该属性是必需的。但是,在收到something 的道具之前,似乎仍在调用render。
此外,我正在使用MyComponent 喜欢
{ valueIsNonNull && <MyComponent something={value} }
在something 被传入之前,render 仍然被调用。
我做错了什么?
【问题讨论】:
标签: javascript reactjs react-native jsx