Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
How can I get rid of so many dispatches?

In my mapDispatchToProps I call draw which draws on my square when pressed, cross or zero. Now the code looks like this:

const mapStateToProps = ({board, players}) => ({board, players});
const mapDispatchToProps =  dispatch => ({
    draw:  (board, players, squareIndex) => {
        if (!board[squareIndex]) {
            if (players[players.turn] === 'X') {
                  dispatch(drawX(squareIndex));
            } else {
                  dispatch(drawO(squareIndex));
            }

            dispatch(checkResult());
            dispatch(toggleTurn());
        }
    }
});

I would like to do something like:

const mapDispatchToProps =  dispatch => ({
    draw
});

it`s possible? Redux-thunk can help me?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should probably only dispatch one action with all relevant infomation here and handle that in mulitple reducers. Even the decision if an X or an O should be drawn should happen in your Reducer, not in your Component.

Just have a case for the same action in multiple reducers. every action will always be forwarded to every reducers.

If you are using Redux Toolkit (which nowadays you really should), you can use extraReducers for that.

Relevant conecptual reading from the Redux Style Guide:

https://redux.js.org/style-guide/style-guide/#model-actions-as-events-not-setters
https://redux.js.org/style-guide/style-guide/#allow-many-reducers-to-respond-to-the-same-action
https://redux.js.org/style-guide/style-guide/#avoid-dispatching-many-actions-sequentially

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda