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

322
Views
¿Cómo puedo hacer un bucle de una API en la consulta de reacción y devolver todos los datos respondidos a la vez?

Estoy tratando de hacer un bucle para obtener la API, la API toma un parámetro y devuelve si el parámetro es verdadero o falso.

He usado useEffect hook y looping the settingTypes y dentro del ciclo estoy llamando a la API y desde la respuesta, estoy almacenando los valores. No quiero hacer como el siguiente código porque cuando se actualiza la API getSettingValues , no se vuelve a obtener la API,

 const [activityTypes, setActivityTypes] = useState<any>([]); useEffect(() => { async function fetchData() { settingTypes.map(async (item: any) => { return await Api.user .getSettingValues(item.channelSettingTypeId) .then((response: any) => { setActivityTypes((oldArray: any) => [ ...oldArray, {[item.channelSettingTypeId]: response.settingValue}, ]); }); }); } fetchData(); }, [activityFeedData.activityList, settingTypes]);

Estoy tratando de hacerlo usando la consulta de reacción. Debajo del código está el enlace de consulta de reacción, useGetSettingValues recibe un parámetro y devuelve si el parámetro es verdadero o falso.

 const useGetSettingValues = (params: any) => useQuery([SETTING_VALUE, params], () => Api.user.getSettingValues(params), { initialData: {data: ''}, });

Mi principal problema es que quiero hacer un bucle en la API useGetSettingValues y almacenar todos los datos de respuesta en un estado. como el siguiente código

 await Api.user .getSettingValues(item.channelSettingTypeId) .then((response: any) => { setActivityTypes((oldArray: any) => [ ...oldArray, {[item.channelSettingTypeId]: response.settingValue}, ]); });

¿Alguna idea de cómo puedo lograrlo?

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!