gpt4 book ai didi

javascript - 您必须将组件传递给 connect 返回的函数。而是收到了 undefined

转载 作者:可可西里 更新时间:2023-11-01 01:24:16 25 4
gpt4 key购买 nike

下面的代码给出了

Uncaught Error: You must pass a component to the function returned by connect. Instead received undefined

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 返回的函数。而是收到了 undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42324317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com