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

275
Views
Las llamadas useEffect dejan de funcionar cuando se llaman demasiadas veces. ¿Por qué?

Tengo un useEffect, que funciona correctamente cuando se hace así.

 async function readUserPosts(profileID){ try { const res = await axios.post(...); setUserPosts(res.data.posts); } catch (err) { console.error(err); } } useEffect(() => { readUserPosts(profileID); }, [profileID])

Pero, si defino el mismo useEffect agregando una segunda función como esta:

 async function readUserPosts(profileID){ try { const res = await axios.post(...); setUserPosts(res.data.posts); } catch (err) { console.error(err); } } useEffect(() => { readUserPosts(profileID); functionX(); }, [profileID])

El useEffect funciona las primeras veces que vuelvo a cargar la página, después de lo cual deja de funcionar. No recibo ningún mensaje de error, incluso cuando envuelvo el try catch alrededor de las 2 funciones. FunctionX es una función asíncrona simple. He sustituido otras funciones de prueba en functionX y produce el mismo resultado. Básicamente, no funcionará cuando se defina una segunda función. ¿Qué salió mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Encierre los dos métodos con useCallback. Aquí hay un método, por ejemplo:

 const readUserPosts = useCallback(async function() { try { const res = await axios.post(...); setUserPosts(res.data.posts); } catch (err) { console.error(err); } }, []);

E intente agregar una dependencia como esta:

 useEffect(() => { readUserPosts(profileID); functionX(); }, [profileID, readUserPosts, functionX])
about 4 years ago · Juan Pablo Isaza Report
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!