我得到一个错误,在使用这个时无法读取undefined的道具?

时间:2018-02-08 18:33:57

标签: javascript reactjs redux redux-thunk

    class CreateMethod extends Component{

    constructor(props) {
        super(props);
      }

    addField(event) {
        console.log('checking',event);
    }
    submit(values){
      let owner = {
        "id": 1,
        "personClass": "EMP",
        "identityNumber": "11001"
      }
      values.owner = owner;
      values.linkedPhases =[]
      values.whoColumns = {};
      if(this.props){
      this.props.pMethodCreate(values);
      }
    }

    clear(){
        console.log('clearing the fields')
    }

    render(){
        // const {submit} = this.props
        console.log('the props are', this.props)
      return(
         <div className="users">
            <SearchSection
                options = {searbarInputs}
                onSubmit={this.submit}
                onClear={this.clear}
            />
            <ValueTable
                column2 = 'Method Details'
                column3 = 'Description'
                column1 = 'Seq No'
                option = { methodDesList }
                label = "Roles"
            />
                <SccButton />
            </div>
      )
   }
}

function mapDispatchToProps(dispatch){
    return bindActionCreators({ pMethodCreate }, dispatch)
}

function mapStateToProps(state){
    return {state}
}

export default connect(mapStateToProps, mapDispatchToProps)(CreateMethod)

我的减速机是:

import { MEATHOD_CREATE } from "../actions/methodAction";
export default function(state=[], action){
switch(action.type){
    case MEATHOD_CREATE :
        console.log('the result is', action.payload)
        return [...state, action.payload]
    default:
        return state;
}
return state;

并且行动是

    export function pMethodCreate(requestBody){
    return (dispatch)=> {
        return axios.post(url+'/save', requestBody).then(response => dispatch(methodCreation(response.data)));
    }
}

export function methodCreation(data){
    return {
        type:MEATHOD_CREATE,
        payload : data
    }
}

我做错了什么,我正在尝试提交redux-form,我对此有点新手? 我试图通过使用redux文档来做到这一点,但没有得到很好的清晰度。如果我试图在componentDidMount()上发送任何get请求然后它正在工作,不知道哪一段代码正在杀死它?

0 个答案:

没有答案