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

92
Vistas
vue-persistedstate reducer with path

im using vue-persistedstate with specific modules to be set persisted only, and it's working well using path attribute.

but when i try to mix it with reducer, the modules set in the path is not working anymore and reducer set all modules persisted. how should i do with reducer?

const persistedstate = new createPersistedState({
  key: "newsportal-vuex",
  storage: window.localStorage, 
  paths: ["auth", "venues", "play", "playWS", "purchaseSettings"], // only the persisted ones
  reducer(val) {
    if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
      // DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
      return {};
    }
    return val; // <-this return ALL MODULES. i want to set only modules in path
  }
});

thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

just realised i need to rebuild the object

reducer(val, paths) {
    if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
      // DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
      return {};
    }

    // make persisted state as in paths
    let reducer = {};

    Object.entries(val).forEach(entry => {
      const [key, value] = entry;
      if (paths.includes(key)) {
        reducer[key] = value;
      }
    });

    return reducer;
  }

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