P
P
pandaa2020-05-22 16:25:27
React
pandaa, 2020-05-22 16:25:27

How to send multiple parameters to action?

Let's say the button in the component takes two parameters

function Component(props) {
  return (
    <div>
      <button onClick={() => props.click_item('par_1', 'par_2')>-</button>
    </div>
  )
}

The question is how to correctly send these two parameters to the action?
function mapDispatchToProps(dispatch) {
  return {
    click_item: (par_1, par_2) => dispatch(click_item(par_1, par_2))
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Zhivagin, 2020-05-22
@Krasnodar_etc

Try just doing:

const mapDispatchToProps = {
    click_item,
}

This is also possible, and throw as many arguments as you want. The main thing is to process them in the action itself.

A
abberati, 2020-05-22
@abberati

click_item is the action creator function. you wrote it with your own hands. write a function that takes two arguments and pass two arguments there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question