下面的代码给出
未捕获的错误:您必须将组件传递给connect返回的函数。而是收到未定义
List.js
import React from 'react'; import { connect, bindActionCreators } from 'react-redux'; import PostList from '../components/PostList'; // Component I wish to wrap with actions and state import postList from '../Actions/PostList' //Action Creator defined by me const mapStateToProps = (state, ownProps) => { return state.postsList } const mapDispatchToProps = (dispatch) => { return bindActionCreators({"postsList":postList},dispatch) } export default connect(mapStateToProps, mapDispatchToProps)(PostList);
PostList.js
import React from 'react' export const PostList = (props) => { return <div>List</div> }
请帮我解决方案?
您正在执行此操作,import PostList from '../components/PostList';因此需要export default在PostList.js文件中使用。
import PostList from '../components/PostList';
export default
否则,您需要做import { PostList } from '../components/PostList';。
import { PostList } from '../components/PostList';
对于感兴趣的人,这是一篇有关es6导入/导出语法的不错的文章:http ://www.2ality.com/2014/09/es6-modules- final.html