Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!