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

78
Visualizações
Reverse state in redux

I'm trying to implement sorting functionality in my notes app but have some problems with it. My sort function must just reverse an array of notes but it does not work.

I have a state with notes:

    export const initialState = {
      notes: [
        {
          id: nanoid(),
          text: '',
          date: '',
        },
      ],
    }

Action:

    export const sortNoteAction = ([notes]) => ({
      type: SORT_NOTE,
      payload: [notes],
    })

Reducer:

    export default function notes(state = initialState, { type, payload }) {
      switch (type) {
        case SORT_NOTE: {
          return {
            ...state,
            notes: [payload].reverse(),
          }
        }
        default:
          return state
      }
    }

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Action:

    export const sortNoteAction = (notes=[]) => ({
      type: SORT_NOTE,
      payload: notes,
    })


Reducer:

    export default function notes(state = initialState, action) {
      switch (action.type) {
        case SORT_NOTE: {
          return {
            ...state,
            notes: action.payload.reverse(),
          }
        }
        default:
          return state
      }
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

I think it doesn't work because you are essentially sorting a list with just one item. If you change [notes] to notes (2 occurrences) and [payload] to payload (1 occurrence) it will probably work

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