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

109
Visualizações
Revert changes in redux store

I've got a simple question.

Now in my App Redux I've got one combined store, and when I fetch data It is set as a part of state.

Then, I've got a React editor which manages state through Redux. When user click on Edit, all the fields become editable. He can mess arround, and after that click on 'Discard' button and get back to initial state of fetched data.

I was trying doing deepcopy of orginal fetched data (after user modify It), but after that I've got proper data in my store, but view still shows the modyfined one (It is connected by te react-redux to the store).

So, my question is, how to do that proper way that the view will show this data. Below is my reducer of editor.

case editorActions.DISCARD_CHANGES:
  return {
    ...state,
    editing: false,
    data: {
      ...state.data,
      ...mapGistToData(payload)
    }
  };

And I pass to It original data like that:

onDiscardClick={discardChanges.bind(null, orginalGist)}

Which comes from

orginal: deepcopy(payload),
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Assume the data are stored in "data" in the state.

Call the actionCreator, by passing the original data from deepcopy during the initial setup.

discardChange(original);

ActionCreator:

export function discardChange(originalData) {
  return {
    type: DISCARD_CHANGES,
    payload: originalData
  }
}

Reducer:

case editorActions.DISCARD_CHANGES:
  return {
    ...state,
    editing: false,
    data: editorActions.payload
  };
over 4 years ago · Santiago Trujillo 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