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

137
Vistas
React useReducer ignores state updates if executed fastly?

Question

Is the normal and expected behavior of a react reducer to ignore state updates in a some kind of "debounced" way?

I have implemented a snack where you can see that with 2 instant state updates via reducer, the screen is only rendered one time.

https://snack.expo.dev/oXd96Nbq8

Check the console logs. Why is this happening?

This is really annoying, since I can't run side-effects since the first state update is not detected? Any ideas?

Code

import React, { useReducer } from 'react';
import Constants from 'expo-constants';

const initialState = {count: 0};

function reducer(state, action) {
  switch (action.type) {
    case 'toggle':
      const newState = { count: state.count === 1 ? 0 : 1 };
      console.log("Expected state", newState);
      return newState;
  }
}


export default function App() {
  const [state, dispatch] = useReducer(reducer, initialState);

  console.log("Rendered state", state);

  const handleOnPress = () => {
    dispatch({type: 'toggle'}); // 1 expected to be rendered... but not rendered because of the rollback?

    try {
      throw new Error("Forced error...");
    } catch(err) {
      console.log(err);
      // Rollback
      dispatch({type: 'toggle'});  // 0 expected to be rendered...
    }
  }

  return (
    <>
      Count: {state.count}
      <button onClick={handleOnPress}>toggle</button>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza
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