本文介绍了您必须将一个组件传递给 connect 返回的函数.而是收到未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码给出了
未捕获的错误:您必须将一个组件传递给 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 文件中.
You are doing import PostList from '../components/PostList';
so you need to use export default
in your PostList.js file.
否则你需要做 import { PostList } from '../components/PostList';
.
感兴趣的人,这里有一篇关于 es6 导入/导出语法的好文章:http://www.2ality.com/2014/09/es6-modules-final.html
To whoever is interested, here is a nice article about es6 import/export syntax: http://www.2ality.com/2014/09/es6-modules-final.html
这篇关于您必须将一个组件传递给 connect 返回的函数.而是收到未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!