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

136
Views
useState vacío a pedido Reaccionar

Estoy usando un botón para realizar una solicitud de recuperación, cuando lo hago y trato de establecer la respuesta en estado de uso, siempre permanece vacío, pero si vuelvo a hacer clic en el botón, ahora me envía la información correctamente.

Este es mi código:

 const fetchUsers = async (page, limit = perPage, search = searchBox, type) => { if (type === 'all') { limit = 100000 } else { setLoading(true); } const dataOnLs = localStorage.getItem('cmtjs') const config = { headers: { "Content-Type": "application/json", apiKey: dataOnLs } , params: { limit, page, search } } const response = await axiosClient(`/products`, config) console.log(response.data.products.docs); // DATA OK if (type === 'all') { setDataToXLS(response.data.products.docs); // **EMPTY** } else { setData(response.data.products.docs); // DATA OK setTotalRows(response.data.products.totalDocs); setLoading(false); } };

No entiendo por qué no configura mi useState (setDataToXLS) con los datos en el primer clic y tengo que hacer clic dos veces para obtener los datos correctamente

about 4 years ago · Santiago Gelvez
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!