在使用es6类声明创建可移动组件时,遇到了这个错误:
Warning: getInitialState was defined on SearchResults,
a plain JavaScript class. This is only supported for
classes created using React.createClass. Did you mean
to define a state property instead?
我将从这个关于流动性文档的例子开始:
我是否正确地声明了我的可流动部件?它在没有初始状态的情况下出错,所以它看起来没有被调用。
import R
React有很多使用PropTypes检查道具值的方法。我常用的一种是React.PropTypes.shape({...})。然而,我最近遇到了这样的情况:我有一个具有动态键/值的对象。我知道每个键应该是一个字符串(以已知的格式),每个值应该是一个int。即使使用自定义的道具验证函数,它仍然假定您知道道具的键。如何使用PropTypes检查对象/形状的键和值是否正确?
...
someArray: React.PropTypes.arrayOf(React.PropTypes.shape({
// How to specify a dynamic string key? Keys are
我有一个React组件,我想强制提供两个支持中的一个--如果两者都没有提供,我希望能够触发一个PropType警告:
MyComponent.propTypes = {
firstProp: PropTypes.string.isRequired, // required only if `otherProp` not provided
otherProp: PropTypes.string.isRequired, // required only if `firstProp` not provided
}
我相信这与AirBnB的是可能的,但我想知道,这是否可以通过反应PropTyp