简体   繁体   English

mapStateToProps中的状态是JSX! React / Redux

[英]state in mapStateToProps is JSX! React / Redux

I am a beginner in React/Redux and ran into this crazy problem where when I console.log the state of mapStateToProps(state), it logged some JSX. 我是React / Redux的初学者并遇到了这个疯狂的问题,当我在console.log状态下调试mapStateToProps(状态)时,它记录了一些JSX。 To elaborate... 详细说明...

import React, { Component } from 'react';
import { connect } from 'react-redux';

import BlogListItem from './blog_list_item';
import selectBlogs from '../selectors/blogs';

const BlogList = (props) => (
    <div className="content-container">
        <div className="list-header">
            <div className="show-for-mobile">Blogs</div>
            <div className="show-for-desktop">Blog</div>
            <div className="show-for-desktop">Posted on</div>
        </div>
        <div className="list-body">
            {
                props.blogs.length === 0 ? (
                    <p className="list-item list-item--message">No Blogs. Write one now!</p>
                ) : (
                    props.blogs.map((blog) => {
                        return <BlogListItem key={blog.id} {...blog} />;
                    })
                )
            }
        </div>
    </div>
);

const mapStateToProps = (state) => {
    console.log(state); // Logs out JSX here
    return {blogs: selectBlogs(state.blogs, state.filters)};
};

export default (mapStateToProps)(BlogList);

The console.log JSX is the following: console.log JSX如下:

ƒ BlogList(props) {
return _react2.default.createElement(
    'div',
    { className: 'content-container' },
    _react2.default.createElement(
        'div',
        { className: 'list-header' },
        _react2.default.…

Which is exactly the const I have defined above! 这正是我上面定义的const! Because of this the app won't run as the parameters passed into selectBlogs() become undefined . 因此,应用程序将无法运行,因为传递给selectBlogs()的参数变为undefined

(If any other details are needed please ask!) (如果需要任何其他细节,请询问!)

导出连接的实例时,您错过了connect ,这就是您收到错误的原因

export default connect(mapStateToProps)(BlogList);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM