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

176
Views
How do I export a redux reducer that uses a prepare function

I am currently working on a anecdotes application, and anytime a user votes on a certain anecdote, it should display a notification then disappear 10 seconds later, however, I am struggling to export my reducer that uses the prepare function that is suppose to, I think, get my multiple arguments ready for the actual reducer. Here is my code in question:

import { createSlice } from "@reduxjs/toolkit";

const notificationSlice = createSlice({
  name: 'notification',
  initialState: '',
  reducers: {
    test: {
      createNotification(state, action) {
        console.log(action)
      },
      prepare(...args) {
        return {
          payload: args
        }
      }
    }
}})

export const { createNotification } = notificationSlice.actions
export default notificationSlice.reducer

I thought I could just export const { test.createNotification } = notificationSlice.actions but that does not work due to the dot in the variable name.

How would I then export my createNotification reducer since test is the first property of the reducers object?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I found the solution, I just name the reducer createNotification with two key values of reducer and prepare

import { createSlice } from "@reduxjs/toolkit";

const notificationSlice = createSlice({
  name: 'notification',
  initialState: '',
  reducers: {
    createNotification: {
      reducer(state, action) {
        console.log(action)
      },
      prepare(...args) {
        return {
          payload: args
        }
      }
    }
}})

export const { createNotification } = notificationSlice.actions
export default notificationSlice.reducer
about 4 years ago · Santiago Gelvez 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!