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

230
Views
¿Cómo obtener respuesta de la función de servicio (axios) con un código de línea en React?

Estoy usando react.js y react-native. Uso react-redux para conectar mis servicios con componentes. A veces llamo a la misma función muchas veces con diferentes parámetros. Quiero escribir esta función una vez y devolver el valor cada vez que la llame. Todo lo que quiero es así;

 let value = this.GetSomething(params); // this is what I want.

Y aquí está mi función para llamar a mi función de servicio;

 GetSomething(params){ this.props.GetValueFromApi(params, ({ VALUE }) => { const status = new Promise( (resolve, reject) => { try { resolve('Operation start') } catch { reject('Operation failed') } }); status.then(() => { console.log("VALUE", VALUE); }) }, () => { alert('error'); } ) }

Aquí está mi función de servicio en otro File.js y lo llamo con redux connect.

 export const GetValueFromApi =(PARAMS,SuccessOperation,FailedOperation) =>{ return() =>{ const body = { params: PARAMS }; axios.post('/api/GetValueFromApi',body) .then(async response => { SuccessOperation({VALUE: await response.data}); }) .catch((error)=>{ FailedOperation(error) }) }

}

Todo lo que quiero obtener es un valor de respuesta como este let value = this.GetSomething(params); después de crear la función GetSomething() una vez en la parte superior del proyecto.

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!