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

124
Views
Cómo agregar un objeto con una relación en la base de datos con redux

Tengo un objeto billingCycle con una lista de objetos de créditos y deudas que el estado tendría este aspecto:

 billingCycle: { id: 1, name: 'March', month: 3, year: 2022, credits: [ { id: 1, name: 'Salary', value: 3700 } ], debts: [ { id: 1, name: 'Car fix', value: 450 } ] }

Pero leí en los documentos de Redux que esta es una mala práctica y se recomienda usar estados normalizados. Entonces mis reductores se ven así:

 const INITIAL_STATE = { list: [], billingCycle: {}, credits: [], debts: [] }; export default function (state = INITIAL_STATE, action) { switch (action.type) { case "BILLING_CYCLES_FETCHED": return { ...state, list: action.payload }; case "BILLING_CYCLES_CREATED": return { ...state, billingCycle: action.payload }; case "BILLING_CYCLES_READED": return { ...state, billingCycle: action.payload }; case "BILLING_CYCLES_UPDATED": return { ...state }; case "BILLING_CYCLES_REMOVED": return { ...state }; case "CREDIT_ADDED": return { ...state, credits: state.credits.concat(action.payload) }; case "CREDIT_REMOVED": return { ...state, credits: state.credits.splice(action.payload, 1) }; case "DEBT_ADDED": return { ...state, debts: state.debts.concat(action.payload) }; case "DEBT_REMOVED": return { ...state, debts: state.debts.splice(action.payload, 1) }; case "RETURN_STATE": return { ...state }; default: return state; } }

Y esta es mi acción de creación:

 export function create(billingCycle) { axios.post(`${BASE_URL}/billingCycles`, billingCycle); return { type: "BILLING_CYCLES_CREATED", payload: billingCycle }; }

Mi pregunta es: ¿cómo puedo enviar un objeto billingCycle a la llamada API con créditos y deudas con él? El método de creación solo agrega el ciclo de facturación sin él. ¿Cómo puedo asignar los objetos respectivos relacionados con él al objeto? ¿En qué parte de mi código hago esta integración?

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!