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

72
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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