Reactjs 失败的属性类型:为“注册”提供的“对象”类型的属性“参数”无效,应为“数组”`

Reactjs 失败的属性类型:为“注册”提供的“对象”类型的属性“参数”无效,应为“数组”`,reactjs,react-router,react-redux,react-router-redux,Reactjs,React Router,React Redux,React Router Redux,我得到这个proptype验证错误“Invalid prop”,如果我将它设置为接收数组,那么它将显示预期的数组但接收对象,在其他情况下,显示相同的错误预期函数但接收对象。 在(signUpdatea:PropTypes.object | | PropTypes.array)中,此警告 如果我只为对象设置PropTypes,那么错误 是类型为对象的“无效属性参数”,并且 如果为数组设置PropTypes,则错误为“无效prop” 对象类型的参数”。有人有办法吗 import React

我得到这个proptype验证错误“Invalid prop”,如果我将它设置为接收数组,那么它将显示预期的数组但接收对象,在其他情况下,显示相同的错误预期函数但接收对象。 在(signUpdatea:PropTypes.object | | PropTypes.array)中,此警告 如果我只为对象设置PropTypes,那么错误 是类型为
对象的“无效属性
参数”
,并且 如果为数组设置PropTypes,则错误为“无效prop”
对象类型的
参数
”。有人有办法吗

     import React,{PropTypes} from 'react';
     import { connect } from "react-redux";
     import * as AuthAction from "../../actions/authActions";
     import * as step2DataActions from "../../actions/step2DataActions";
     import update from 'react-addons-update';

 class SIGNUP extends React.Component{
 constructor(props){
      super(props);

 this.state = {
      teacherId:props.signupData.teacherId,
      data: props.signupData.step4.data,

      endTime: props.signupData.step4.endTime,
      head: props.signupData.step4.head,
      errorInput:'',
      errorField: '',
      valid: true,
      };
      }


      submitStepSignupForm(){
      let step3 = {single_classes:false,multiple_classes:true};
      let step4 =      {head:this.state.head,startTime:this.state.startTime,endTime:this.state.endTime,data:this.state.data};
      let submitData = {};
      submitData['teacher_id'] = this.state.teacherId;
      submitData['firstname'] = this.props.signupData.firstname;
      submitData['lastname'] = this.props.signupData.lastname;
      submitData['state'] = this.props.signupData.State;
      submitData['zipcode'] = this.props.signupData.zipcode;
      submitData['prefix'] = this.props.signupData.prefix;
      submitData['step2'] = this.props.step2Data;
      submitData['step3'] = step3;
      submitData['step4'] = step4;
      this.props.signupStep4(submitData);
      }
      closeModal(){
      this.props.scheduleData.dataExist = false;
      }

      render(){
      let tableStyle = {
           align:"center"
      };
      let list = this.state.data.map((p,index) =>{
           return (
                <tr className="grey2" key={index}>
                     {Object.keys(p).filter(k => k !== 'id').map(k => {
                           return (<td className="grey1" key={p.id+''+k}><div suppressContentEditableWarning="true" contentEditable="true"
                          value={k} onInput={this.editColumn.bind(this,{p},{k})}>{p[k]}</div></td>);
                     })}
                </tr>
           );
      });

      let startList = null;
      startList = this.state.startTime.map((obj,index)=>{
           let keyName = Object.keys(obj)[0];
           return(
                <td className="" key={index}><TimePicker start="08:00" end="18:00" step={1} name="C1StartTime" value={obj.StartTime} onChange={this.changeStartTime.bind(this,index,keyName)} /></td>
           );
      });

      let endList = null;
      endList = this.state.endTime.map((obj,index)=>{
           let keyName = Object.keys(obj)[0];
           return(
                <td className="" key={index}><TimePicker start="08:00" end="18:00" step={1} value={obj.EndTime} onChange={this.changeEndTime.bind(this,index,keyName)} /></td>
           );
      });

      let head = null;
      head = this.state.head.map((obj,index)=>{
           return (
                <td className="grey1" key={index}>{obj['class']}</td>
           );
      });


      return (
           <fieldset className="step-4">
                <div className="heading">
                     <h3>Tell us about your schedule</h3>
                     {/*<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit </p>*/}
                </div>
                <div className="schedule table-responsive">
                     <table cellSpacing="3" id="mytable" style={tableStyle}>
                          <tbody>
                               <tr className="grey2" >
                                    {head}
                               </tr>
                               <tr className="grey2" >
                                    <td className="">Start Time</td>
                                    {startList}
                               </tr>
                               <tr className="grey2" >
                                    <td className="">End Time</td>
                                         {endList}
                               </tr>

                               {list}</tbody>
                     </table>
                     <p><a id="add_row" className="btn btn-default" onClick={this.appendColumn}>Add +</a>
                     <a id="add_row" className="btn btn-default" onClick={this.removeColumn}>Remove -</a>
                     <span className="inputError" >{this.state.errorInput}</span>
                     <span className="inputError" >{this.state.errorField}</span>
                </p>
                </div>
                <input type="button" name="previous" className="previous pre-btn action-button" value="Previous" />
                {(this.state.valid)?(<input type="submit" name="submit" className="submit1 action-button1" value="Submit" onClick={this.submitStepSignupForm.bind(this)}/>):(<input type="submit"  name="submit" className="disable-step4" value="Submit"  />)}
           </fieldset>
      );
      }
      }
      STEP4SIGNUP.propTypes = {
       signupData : PropTypes.object || PropTypes.array,
       getSchedule : PropTypes.object || PropTypes.array,
       step2Data : PropTypes.object || PropTypes.array,
       scheduleData : PropTypes.object || PropTypes.array,
       signupStep4 : PropTypes.func
      };
      const mapStateToProps = (state) => {
       return {
        user: state,
        step2Data: state.step2Data.step2Data,
        scheduleData: state.step2Data.scheduleData,
        step4Data: state.step4Reducer.step4
      };
     };
     const mapDispatchToProps = (dispatch) => {
      return {
           signupStep4: submitData =>       dispatch(AuthAction.signupStep4(submitData)),
           getSchedule: (teacher_id) => dispatch(step2DataActions.getSchedule(teacher_id)),
 };
 };

    export default connect(mapStateToProps,mapDispatchToProps)(STEP4SIGNUP);
import React,{PropTypes}来自'React';
从“react redux”导入{connect};
从“../../actions/authActions”导入*作为AuthAction;
将*作为step2DataActions从“../../actions/step2DataActions”导入;
从“react addons update”导入更新;
类注册扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
teacherId:props.signUpdatea.teacherId,
数据:props.signupdatea.step4.data,
endTime:props.signupdatea.step4.endTime,
head:props.signupdatea.step4.head,
错误输入:“”,
错误字段:“”,
有效:对,
};
}
submitStepSignupForm(){
设step3={single_classes:false,multiple_classes:true};
让step4={head:this.state.head,startTime:this.state.startTime,endTime:this.state.endTime,data:this.state.data};
让submitData={};
submitData['teacher_id']=this.state.teacherId;
submitData['firstname']=this.props.signupdatea.firstname;
submitData['lastname']=this.props.signupdatea.lastname;
submitData['state']=this.props.signupdatea.state;
submitData['zipcode']=this.props.signupdatea.zipcode;
submitData['prefix']=this.props.signupdatea.prefix;
submitData['step2']=this.props.step2Data;
提交数据['step3']=step3;
提交数据['step4']=step4;
this.props.signupStep4(submitData);
}
closeModal(){
this.props.scheduleData.dataExist=false;
}
render(){
让表样式={
对齐:“居中”
};
让list=this.state.data.map((p,index)=>{
返回(
{Object.keys(p).filter(k=>k!='id').map(k=>{
返回({p[k]});
})}
);
});
设STARTIST=null;
startList=this.state.startTime.map((对象,索引)=>{
让keyName=Object.keys(obj)[0];
返回(
);
});
让endList=null;
endList=this.state.endTime.map((obj,index)=>{
让keyName=Object.keys(obj)[0];
返回(
);
});
设head=null;
head=this.state.head.map((对象,索引)=>{
返回(
{obj['class']}
);
});
返回(
告诉我们你的日程安排
{/*Lorem ipsum door sit amet,concetetur adipising elit

*/} {head} 开始时间 {startist} 结束时间 {endList} {list} 加+ 除去- {this.state.errorInput} {this.state.errorField}

{(this.state.valid)?():()} ); } } 步骤4 signup.propTypes={ SignUpdatea:PropTypes.object | | PropTypes.array, getSchedule:PropTypes.object | | PropTypes.array, step2Data:PropTypes.object | | PropTypes.array, scheduleData:PropTypes.object | | PropTypes.array, signupStep4:PropTypes.func }; 常量mapStateToProps=(状态)=>{ 返回{ 用户:国家, step2Data:state.step2Data.step2Data, scheduleData:state.step2Data.scheduleData, step4Data:state.step4Reducer.step4 }; }; const mapDispatchToProps=(调度)=>{ 返回{ signupStep4:submitData=>dispatch(AuthAction.signupStep4(submitData)), getSchedule:(教师id)=>分派(step2DataActions.getSchedule(教师id)), }; }; 导出默认连接(mapStateToProps、mapDispatchToProps)(步骤4注册);
当你写
SignUpdatea:PropTypes.object | | PropTypes.array时
你基本上是说

if(PropTypes.object){
   return PropTypes.object;
} else {
   return PropTypes.array;
}
换句话说,由于
PropTypes.object
的计算结果总是
true
,因此您一直在将您的道具声明为
PropTypes.object

如果要针对多个类型验证道具,请使用
oneOfType

  // An object that could be one of many types
  optionalUnion: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number,
    PropTypes.instanceOf(Message)
  ])

你应该决定你的道具将要获取的数据类型,但是错误是无效的道具类型object当你找到问题的解决方案时,注意与社区共享以备将来参考。谢谢