下面的代码给出



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';,因此需要在PostList.js文件中使用export default

否则,您需要执行import { PostList } from '../components/PostList';

对于感兴趣的人,这是一篇有关es6导入/导出语法的不错的文章:http://www.2ality.com/2014/09/es6-modules-final.html

关于javascript - 您必须将组件传递给connect返回的函数。而是收到未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42324317/

10-09 19:02