reactjs

Map State to Props using React + Redux

import React from "react";
import { connect } from "react-redux";

const mapStateToProps = state => {
    return { articles: state.articles };
}

const ConnectedList = ({ articles }) => (
    <ul>
        { articles.map(article => (
            <li className="item" key={article.id}>{ article.title }</li>
        )) }
    </ul>
);

const List = connect(mapStateToProps)(ConnectedList);


class FirstComponent extends React.Component {
    render() {
        return (
            <div>
                <div className="Hello">Hello ankit this i</div>
                <List></List>
            </div>
        );
    }
}

export default FirstComponent;

The code snippet describes the process of connecting redux state data to React components. We are using the article list to show on Blog page using this code.

Was this helpful?