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

114
Views
¿Reaccionar el estado de recuperación nativo no se actualiza?
 const [restaurantsData,setrestaurantsData]=useState([]) useEffect(()=>{ const getData = async () => { await fetch('http://localhost:5000/api/v1/res/') .then((response) => response.json()) .then((json) => {setrestaurantsData(json.data),console.log(restaurantsData)}) .catch((error) => console.error(error)) .finally(); }; getData(); console.log(id) console.log("photo",restaurantsData.photo) },[]) useEffect(()=> { for (const {type: t} of menuDetailedData) { routes.push({key:i,title:t}) i++; } console.log("routes",routes) let acc=[] for(let i=0; i<menuDetailedData.length-1;i++) { if(routes[i].title===routes[i+1].title) { acc.push(routes[i]) } } setroutes(routes.filter(item => !acc.includes(item))) console.log("acc",acc) },[])

Los datos del restaurante en este código siempre son nulos. Sin embargo, tengo el mismo código en la pantalla anterior que funciona perfectamente bien. No sé por qué el estado no está actualizando el archivo . Puede ser useeffect está causando problemas

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

0

Para ver los cambios de restaurantsData debes usar un useEffect para verificar ese cambio:

Como esto:

 useEffect(()=> { console.log(restaurantsData) // if the restaurantsDate is still null here probably your service its not working correctly //NOTE: as I am passing the restaurantsData in the dependency array of the useEffect every time that restaurantsData change this will execute. }, [restaurantsData])
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!