Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Redux is not updating state in react

Redux is not updating state in react in Safari browser only but in chrome it's working fine. when I console the action in case VISITS_SEARCH: I get empty array in Safari. however, I get valid array in chrome console

export const visitsReducer = (state = initialState, action) => {
console.log("🚀 ~ file: visits-reducer.js ~ line 28 ~ visitsReducer ~ action", action)
  return produce(state, (draftState) => {
    switch (action.type) {
      case GET_VISIT_LIST:
        draftState.isWorking = true;
        draftState.error = null;
        return;

      case GET_VISIT_LIST_SUCCESS:
        draftState.isWorking = false;
        draftState.visits = action.visits;
        console.log("🚀 ~ file: visits-reducer.js ~ line 39 ~ returnproduce ~ action", action)
        return;

      case VISITS_SEARCH:
        draftState.searchResults = action.visits;
        console.log("🚀 ~ file: visits-reducer.js ~ line 80 ~ returnproduce ~ action", action)
        
        return;

      default:
        return;
    }
  });
};
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

in redux, you should never change the state that you get from argument. instead you should return the values that you want to change and your value that you dont want to change. because of this you have this problem. you should do this:

  case GET_VISIT_LIST:
    return {
      ...state,
      isworking: true,
      error: null
    }

changing the state that you get from argument in redux toolkit is correct and you can use redux toolkit

about 4 years ago · Juan Pablo Isaza Relatório

0

I fixed it. It has no relation with fetch at all after wasting time for checking this. In a sort by date function the date was 9999-1-1 which's invalid for Safari I had to change to be 9999-01-01

about 4 years ago · Juan Pablo Isaza Relatório

0

I'm assuming you populate data with fetch, This is common issue according to Redux Docs:

We use fetch API in the examples. It is a new API for making network requests that replaces XMLHttpRequest for most common needs. Because most browsers don't yet support it natively, we suggest that you use cross-fetch library:

// Do this in every file where you use `fetch`
import fetch from 'cross-fetch' 

Internally, it uses whatwg-fetch polyfill on the client, and node-fetch on the server, so you won't need to change API calls if you change your app to be universal.

Be aware that any fetch polyfill assumes a Promise polyfill is already present. The easiest way to ensure you have a Promise polyfill is to enable Babel's ES6 polyfill in your entry point before any other code runs:

// Do this once before any other code in your app  import
'babel-polyfill'
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda