score:1

Accepted answer

you should forward (or proxy) the id to the action creator

const mapdispatchtoprops = dispatch => ({
  addmarket: () => dispatch(actions.addmarket()),
  addcard: (id) => dispatch(actions.addcard(id)) // <-- pass id to action creator
});

ui, now passing props.id will work.

onclick={() => props.addcard(props.id)}

fun fact: you might not need the mapdispatchtoprops function

the redux connect hoc will automagically wrap actions in mapdispatchtoprops in a call to dispatch, so you can write a mapdispatchtoprops that looks like this

const mapdispatchtoprops = {
  addmarket: actions.addmarket,
  addcard: actions.addcard
};

and since the function signature of addcard already takes an id

export const addcard = (marketid) => ({
  type: types.add_card,
  payload: marketid,
});

then your onclick code will still work as expected.


Related Query

More Query from same tag