Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
¿Cómo puedo deshacerme de tantos despachos?

En mi mapDispatchToProps, llamo dibujar, que se dibuja en mi cuadrado cuando se presiona, cruz o cero. Ahora el código se ve así:

 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()); } } });

Me gustaría hacer algo como:

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

es posible? Redux-thunk puede ayudarme?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Probablemente solo deba enviar una acción con toda la información relevante aquí y manejarla en múltiples reductores. Incluso la decisión de dibujar una X o una O debe ocurrir en su Reductor, no en su Componente.

Solo tenga un caso para la misma acción en múltiples reductores. cada acción siempre se reenviará a todos los reductores.

Si está utilizando Redux Toolkit (que hoy en día realmente debería), puede usar extraReducers para eso.

Lectura conceptual relevante de la Guía de estilo de Redux:

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-secuencialmente

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!