【发布时间】:2020-05-30 23:07:16
【问题描述】:
所以我试图使用路由将参数传递给反应组件,同时也使用组件类道具。这是我在做什么
import { loadSchemes, } from '../../actions/schemes;
export class Schemes extends Component {
constructor(props) {
super(props);
const { match: { params } } = this.props;
this.state = {
client_id: params.pk,
}
}
componentDidMount() {
this.props.loadSchemes();
}
render(){
return(
<div>
{this.props.schemes_list.map((scheme,index)=><p key={index}>{scheme}</p>)}
</div>
)
}
}
const mapStateToProps = (state) => ({
schemes_list: state.schemes,
});
export default connect(mapStateToProps,{ loadSchemes,})(Schemes);
我有一个指向这个组件的 url 作为
<Route path="/client/:pk/schemes" component={Schemes}/>
问题是我得到一个错误 this.props.schemes_list is undefined 并且 this.props.loadSchemes is undefined
请帮助我使用 react-redux
【问题讨论】:
-
import { loadScheme, } 是单数,你在哪里传递“schemes_list”我看不到
-
导入是一个错字,它们都是 loadSchemes,让我编辑问题,schemes_list 也来自 scheme reducer。
标签: reactjs react-redux