2017-02-19 12 views
6

Đoạn code dưới đây mang đến choBạn phải chuyển một thành phần vào hàm được trả về bằng kết nối. Thay vì nhận được xác định

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> 
} 

Xin hãy giúp tôi với một giải pháp?

+1

séc Postlist nhập khẩu –

+0

Không có vấn đề với PostList nhập khẩu –

+2

Bạn có chắc chắn bạn không phải một trong hai mặc định xuất khẩu hoặc nhập {PostList} từ '../components/PostList'; – noveyak

Trả lời

7

Bạn đang thực hiện import PostList from '../components/PostList'; để bạn cần sử dụng export default trong tệp PostList.js của mình.

Nếu không, bạn cần thực hiện import { PostList } from '../components/PostList';.

Để bất cứ ai quan tâm, đây là một bài viết thú vị về cú pháp es6 nhập khẩu/xuất khẩu: http://www.2ality.com/2014/09/es6-modules-final.html

+0

Trong trường hợp của tôi, tôi đã sao chép mã từ một thành phần khác và thay đổi mọi thứ ngoại trừ tên trong khai báo 'propTypes' – Snailer

Các vấn đề liên quan