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

173
Views
What is extraReducers map object notion

When read redux toolkit offical documet, I saw this in createSlice section:

const incrementBy = createAction('incrementBy')

createSlice({
  name: 'counter',
  initialState: 0,
  reducers: {},
  extraReducers: {
    [incrementBy]: (state, action) => {. ///what is this
      return state + action.payload
    },
    'some/other/action': (state, action) => {},
  },
})

I don't understand why we have array here. Why do we use string here and why we use this in an array ( [incrementBy] )?

Please help, thank you a lots

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is not an array, instead this is computed properties. This will add key to an object at run-time

let prop = "name";
const obj = {
  [prop]: "Stackoverflow",
};
console.log(obj);

extraReduce is an object and in the code incrementBy will give property name, also you are assigning a function to that property name.

let prop = "getSum";
const obj = {
  [prop]: (arr) => {
    return arr.reduce((acc, curr) => acc + curr, 0);
  },
};
console.log(obj[prop]([1, 2, 3, 4, 5]));
console.log(obj.getSum([1, 2, 3, 4, 5]));

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!