The code below gives
下面的代码给出了
Uncaught Error: You must pass a component to the function returned by connect. Instead received undefined
未捕获错误:必须将组件传递给connect返回的函数。而不是收到未定义
List.js
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
PostList.js
import React from 'react'
export const PostList = (props) => {
return <div>List</div>
}
Please help me with a solution?
请帮我个忙好吗?
1 个解决方案
#1
11
You are doing import PostList from '../components/PostList';
so you need to use export default
in your PostList.js file.
您正在从'../组件/PostList'进行导入PostList;所以需要在PostList中使用export default。js文件。
Otherwise you need to do import { PostList } from '../components/PostList';
.
否则需要从'../组件/PostList'中导入{PostList};
To whoever is interested, here is a nice article about es6 import/export syntax: http://www.2ality.com/2014/09/es6-modules-final.html
对于感兴趣的人,这里有一篇关于es6导入/导出语法的好文章:http://www.2ality.com/2014/09/es6-modules-final.html
#1
11
You are doing import PostList from '../components/PostList';
so you need to use export default
in your PostList.js file.
您正在从'../组件/PostList'进行导入PostList;所以需要在PostList中使用export default。js文件。
Otherwise you need to do import { PostList } from '../components/PostList';
.
否则需要从'../组件/PostList'中导入{PostList};
To whoever is interested, here is a nice article about es6 import/export syntax: http://www.2ality.com/2014/09/es6-modules-final.html
对于感兴趣的人,这里有一篇关于es6导入/导出语法的好文章:http://www.2ality.com/2014/09/es6-modules-final.html