score:2

Accepted answer

for what it's worth - do not pass around setstate - that's an anti-pattern.

this is the common syntax/construction for connect regarding a component :

import { connect } from 'react-redux'

const todoitem = ({ todo, destroytodo }) => {
  return (
    <div>
      {todo.text}
      <span onclick={destroytodo}> x </span>
    </div>
  )
}

const mapstatetoprops = state => {
  return {
    todo: state.todos[0]
  }
}

const mapdispatchtoprops = dispatch => {
  return {
    destroytodo: () =>
      dispatch({
        type: 'destroy_todo'
      })
  }
}

export default connect(
  mapstatetoprops,
  mapdispatchtoprops
)(todoitem)

per your question, let's break the syntax down a little easier without all of the properties and look at it as simply as possible :

(dispatch) => {
    test : (dispatch, setstate /* don't do this */) => { 
        dispatch('do a thing')
    } 
}

score:7

the mapdispatchtoprops is a simple function which returns an object. the object's key is a name of your method and value is your actual function.

your method should look like this:

const mapdispatchtoprops = dispatch => {
   return {
     foomethod: () => {},
     barmethod: () => {},
   };
};

connect(undefined, mapdispatchtoprops)(<your component>);

after that, you can get access to these methods via props.


Related Query

More Query from same tag