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

139
Views
Redux Toolkit caseReducers omiten preparar la devolución de llamada en la función de reducción

Tengo un reductor para agregar comentarios de la siguiente manera

 addComment: { reducer: (state,action)=>{ const { newId, comment } = action.payload console.log(newId) // functions that create an new comment entry with the newID and update state }, prepare: (input) =>{ return { payload: { ...input, newId: nanoid(), } } }

Si llamo a dispatch dentro de mi aplicación de la siguiente manera, console.log muestra la identificación generada por nanoid(). Hasta aquí todo bien.

 dispatch(addComment({comment: comment}))

Sin embargo, si llamo al reductor dentro de otro reductor usando caseReducers, console.log devuelve undefined

 commentSlice.caseReducers.addComment(state,{ payload: { comment : comment } })

¿Cómo hago para que se ejecute la devolución de llamada de preparación cuando uso caseReducers.

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

0

Según los documentos , parece que si va a invocar usando la forma caseReducer, debe incluir el "tipo":

 const slice = createSlice({ name: 'test', initialState: 0, reducers: { increment: (state, action: PayloadAction<number>) => state + action.payload, }, }) // now available: slice.actions.increment(2) // also available: slice.caseReducers.increment(0, { type: 'increment', payload: 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!