xyz-data / redux-seeds

Redux Seeds : React family's all in one!
MIT License
0 stars 0 forks source link

react-redux #10

Open xgqfrms-GitHub opened 7 years ago

xgqfrms-GitHub commented 7 years ago

react-redux

源码分析

https://github.com/reactjs/react-redux/tree/master/src

xgqfrms-GitHub commented 7 years ago

react-redux

https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options


import {connect} from 'react-redux';

// mapStateToProps()
const mapStateToProps = (state, ownProps) => {
    return {
        active: ownProps.filter === state.visibilityFilter
    };
};

// mapDispatchToProps()
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        onClick: () => {
            dispatch(setVisibilityFilter(ownProps.filter))
        }
    };
};

// connect
// connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
const FilterLink = connect(
    mapStateToProps,
    mapDispatchToProps
)(Link);
xgqfrms-GitHub commented 7 years ago

react-redux

https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options

http://redux.js.org/docs/basics/UsageWithReact.html


import {connect} from 'react-redux';

// mapStateToProps()
const mapStateToProps = (state, ownProps) => {
    return {
        active: ownProps.filter === state.visibilityFilter
    };
};

// mapDispatchToProps()
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        onClick: () => {
            dispatch(setVisibilityFilter(ownProps.filter))
        }
    };
};

// connect
// connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
const FilterLink = connect(
    mapStateToProps,
    mapDispatchToProps
)(Link);