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

119
Views
Check if a there is nothing in the redux store, and fill the store

I have selectedProject in my redux store which contains projects. However, when there is no project in the store, I would like to fill the project array with the lastOpenedProject's id.

here is what I have for now:

  const selectedProjectIsEmpty =()=>{
    if(selectedProject.length === 0){
        dispatch(selectedProject: projects.filter((el) => el.id === lastOpenProject))   
    }
}
selectedProjectIsEmpty()
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Which library do you use? Redux or Redux Toolkit?

about 4 years ago · Juan Pablo Isaza Report

0

you cannot directly mutate redux states instead you dispatch an action which calls the appropriate reducer to update the state values,In your dispatch action function you are directly assigning value to the redux state instead create an action function which takes an array as an parameter and updates the redux state ,like this

Using redux toolkit :

....

   reducers : {

          setSelectedProjects : (state,{payload}) => {
              state.selectedProjects = payload;
          }
          }
          
....          

you always dispatch actions to update state!,dont mutate values!.

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!