我有以下组件 ( radioOther.jsx):
 'use strict';
 //module.exports = <-- omitted in update
   class RadioOther extends React.Component {
     // omitted in update 
     // getInitialState() {
     //    propTypes: {
     //        name: React.PropTypes.string.isRequired
     //    }
     //    return {
     //       otherChecked: false
     //   }
     // }
     componentDidUpdate(prevProps, prevState) {
         var otherRadBtn = this.refs.otherRadBtn.getDOMNode();
         if (prevState.otherChecked !== otherRadBtn.checked) {
             console.log('Other radio btn clicked.')
             this.setState({
                 otherChecked: otherRadBtn.checked,
             });
         }
     }
     onRadChange(e) {
         var input = e.target;
         this.setState({
             otherChecked: input.checked
         });
     }
     render() {
         return (
             <div>
                 <p className="form-group radio">
                     <label>
                         <input type="radio"
                                ref="otherRadBtn"
                                onChange={this.onRadChange}
                                name={this.props.name}
                                value="other"/>
                         Other
                     </label>
                     {this.state.otherChecked ?
                         (<label className="form-inline">
                             Please Specify:
                             <input
                                 placeholder="Please Specify"
                                 type="text"
                                 name="referrer_other"
                                 />
                         </label>)
                         :
                         ('')
                     }
                 </p>
             </div>
         )
     }
 };
在使用 ECMAScript6 之前一切都很好,现在我收到 1 个错误,1 个警告,我有一个后续问题:
错误:未捕获的类型错误:无法读取 null 的属性“otherChecked”
警告: getInitialState 是在 RadioOther 上定义的,它是一个普通的 JavaScript 类。这只支持使用 React.createClass 创建的类。你的意思是定义一个状态属性吗?
任何人都可以看到错误所在,我知道这是由于 DOM 中的条件语句引起的,但显然我没有正确声明其初始值?
我应该让getInitialState静态
如果 getInitialState 不正确,在哪里声明我的 proptypes 的合适位置?
更新:
   RadioOther.propTypes = {
       name: React.PropTypes.string,
       other: React.PropTypes.bool,
       options: React.PropTypes.array }
   module.exports = RadioOther;
@ssorallen,这段代码:
     constructor(props) {
         this.state = {
             otherChecked: false,
         };
     }
产生"Uncaught ReferenceError: this is not defined",而下面更正了
     constructor(props) {
     super(props);
         this.state = {
             otherChecked: false,
         };
     }
但是现在,单击另一个按钮会产生错误:
Uncaught TypeError: Cannot read property 'props' of undefined