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

86
Views
¿Cómo agregar valores a la matriz de estado anidado en la carga útil del reductor?

Estoy tratando de agregar valores de una respuesta a mi estado Redux en el reductor. Tengo un objeto de estado que se parece a esto:

 state: { currentUser: { loggedIn: boolean, follows: [string array], following: [string array], uid: string } }

Hay otros, pero esto muestra la forma que necesito agregar. Cuando se agrega un follow de una respuesta, necesito agregarlo a la following matriz. Cuando trato de acceder a él, dice que "posiblemente podría ser nulo". ¿Hay algo que deba hacer? Estoy mirando específicamente la acción ADD_FOLLOW.

 import actions from '../actions/userActions' const initialState = { loggedIn: false, currentUser: null } export const userReducer = (state: any = initialState, action: any) => { switch (action.type) { // User logic will go here case actions.LOG_IN: { console.log('user logged in! Action obj: ', action) sessionStorage.setItem('user_object', JSON.stringify(action.payload)) return { ...state, loggedIn: true, currentUser: { ...action.payload, uid: action.payload._id } } } case actions.LOG_OUT: { sessionStorage.clear() return initialState } case actions.REAUTH: { return state } case actions.UPDATE_INFO: { console.log('payload for update user: ', action.payload) return { ...state, currentUser: { ...action.payload } } } case actions.ADD_FOLLOW: { return { ...state, currentUser: { follows: [ ...state.currentUser.follows || [], action.payload.resource_id ] } } } default: { return state } } }
about 4 years ago · Juan Pablo Isaza
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!