I
I
ironmansl2019-11-20 00:24:07
React
ironmansl, 2019-11-20 00:24:07

How to pass multiple actions to matchDispatchToProps? And in mapStateToprops there are several states (for each reducer)?

function mapStateToProps(state){ 
    return {
        cars: state.cars
    };
}

cars is a reducer, the exact combineReducer property in which the reducer is stored
In mapStateToProps, you need to pass the state of the reducer - motocycle
function matchDispatchToProps(dispatch){ 
    return bindActionCreators({select: select}, dispatch) 
}

select is action
It is also necessary to pass action - delete in matchDispatchToProps
How to register?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ant Li, 2019-11-20
@ironmansl

const mapStateToProps = ({ cars, motocycle }) => ({ cars, motocycle })

and
const matchDispatchToProps = dispatch => ({
   select: () => dispatch(select),
   delete: () => dispatch(delete)
})

if you need to forward id in delete, then rewrite action delete like this:
delete: (id) => dispatch(delete(id))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question