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

355
Views
React-Native: no se puede realizar una actualización de estado de React en un componente desmontado

¿Cuál es el uso correcto de UseEffect en react-Native? este es el 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 una función de limpieza useEffect.

 const [task, setTask] = useState(null); const fetchData = React.useCallback( () => { const newTask = InteractionManager.runAfterInteractions( async () => { try { const _token = await AsyncStorage.getItem('@token'); let UserId = await AsyncStorage.getItem('@UserID') setToken(_token); fetchParents(UserId, _token); fetchStudent(UserId, _token); fetchTeacher(UserId, _token); UserProfile(UserId, _token) } catch(e) { console.log(e); } }); setTask(newTask) }, []) useEffect( () => { fetchData() // to cleanup tasks on component will mount return () => { task.cancel(); setTask(null) // to remove task from state }, []} ); const fetchParents = async (UserId, _token) => { try { fetch(config.API_URL + '/Parents/Application/Access/10/'+UserId, { method: 'GET', headers: { //Headers 'Authorization': 'Bearer '+ _token, 'Content-Type': 'application/json', }, }) .then((response) => response.json().then(data=>({status:response.status, body:data})) ) .then((response) => { if(response.status==200) { if(response.body.length > 0) { setParent(response.body[0].udf_Users_IsHaveApplicationAccess) }else{ console.log("err"); } }else{ console.log("error"); } }); } catch (e) { console.log(e); } } const fetchStudent = async (UserId, _token) => { .....//same code in fetchParents } const fetchTeacher = async (UserId, _token) => { .....//same code in fetchParents } const UserProfile = async (UserId, _token) => { .....//same code in fetchParents }

ingrese la descripción de la imagen aquí

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

0

Hacer esto

 const fetchData = React.useCallback( () => { const newTask = InteractionManager.runAfterInteractions( async () => { const _token = await AsyncStorage.getItem('@token'); let UserId = await AsyncStorage.getItem('@UserID') setToken(_token); fetchParents(UserId, _token); fetchStudent(UserId, _token); fetchTeacher(UserId, _token); UserProfile(UserId, _token) }); setTask(newTask) }, [])

// tu efecto de uso

 useEffect(() => { fetchData() }, [reRender]);
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!