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

198
Views
Usar setState en la función asíncrona y luego llamarlo en useEffect

Aquí está mi función:

 functon ABCComponent({ navigation }){ const testPostID = "1234567891011"; const [post, setPost] = useState(""); const getPostById = async(postID)=>{ await axios.get(`http://localhost:5000/posts/post/${postID}`) .then((response) =>{ dispatch(setLoading(true)); dispatch(setSuccess(true)); dispatch(setLoading(false)); response.data.message.map((post, index) =>{ setPost(post); // I think it's complaining about this line }); }).catch((error) =>{ console.log("err: ", error); dispatch(setLoading(true)); dispatch(setSuccess(false)); dispatch(setLoading(false)); dispatch(setMessage(`${error}`)); }); }; useEffect(() =>{ getPostById(testPostID); }, []); }

Estoy teniendo el siguiente error:

Advertencia : no se puede realizar una actualización de estado de React en un componente desmontado. Esto no es operativo, pero indica una pérdida de memoria en su aplicación. Para solucionarlo, cancele todas las suscripciones y tareas asincrónicas en %s.%s, una función de limpieza useEffect, en ABCComponent.

¿Cuál es la mejor manera de solucionar esto?

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!