mapStateToProps仅传递一个对象

时间:2019-02-17 16:18:18

标签: reactjs react-redux

mapStateToProps在一个数组中有三个对象,但是当传递给渲染时,它仅传递一个对象。如何在渲染地图功能中获取所有对象...下面是我的代码。

class AppliedCandidates extends Component {

render() {
    const {appliedjob} = this.props
    console.log('================+++++====================');
    console.log("appliedjob ", appliedjob);
    console.log('================+++++====================');
    return (
       <div>
            { appliedjob && appliedjob.map(job => {

            return (<div>
                    <h5>{job.jobid}</h5>
                    <h6>{job.candidatephoneno}</h6>
                    </div>
                )})
            }
       </div> 
    );
}
}

const mapStateToProps = (state) => {
console.log("state" , state); 
return {
    appliedjob:state.getAppliedJobs.appliedjob
}
   }

渲染时:

appliedjob  [{…}]

在mapstatetoprops

getAppliedJobs:
appliedjob: (3) [{…}, {…}, {…}]
authError: ""
__proto__: Object

2 个答案:

答案 0 :(得分:1)

尝试一下:

您必须将所有状态值分别映射到道具,或者还可以映射整个状态对象:

这应该可以:

`const mapStateToProps = (state) => {
    console.log("state" , state); 
    return {
        appliedjob:state.getAppliedJobs.appliedjob,
        getAppliedJobs: state.getAppliedJobs.getAppliedJobs,
        authError: state.getAppliedJobs.authError
   }
})`

答案 1 :(得分:0)

state.getAppliedJobs.appliedjob 

好像您正在尝试从redux商店中调用函数,而不仅仅是映射商店的状态,请尝试

appliedjob:state.appliedjob

并获得Redux devtools,它们对所有这些东西都非常有帮助