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

204
Views
No puedo acceder al elemento html dentro de useEffect

Quiero generar un control de itinerario (elemento de tabla) generado en <RoutingMachine /> . Pero no puedo acceder al elemento html en useEffect porque aún no existe.

 const Routing = ({ pointA, pointB }) => { const dispatch = useDispatch() const createLayer = () => { const instance = L.Routing.control({ waypoints: [ L.latLng(pointA.position.lat, pointA.position.lng), L.latLng(pointB.position.lat, pointB.position.lng) ], lineOptions: { styles: [{ color: "red", weight: 4 }] }, }); return instance; }; const RoutingMachine = createControlComponent(createLayer); useEffect(() => { let routeInfo = document.querySelectorAll('tr') console.log(routeInfo) // array with 0 elements }, []); return <RoutingMachine /> };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Puedes probar esto (con useRef() ):

 const Routing = ({ pointA, pointB }) => { const dispatch = useDispatch() const mounted = useRef(true) const createLayer = () => { const instance = L.Routing.control({ waypoints: [ L.latLng(pointA.position.lat, pointA.position.lng), L.latLng(pointB.position.lat, pointB.position.lng) ], lineOptions: { styles: [{ color: "red", weight: 4 }] }, }); return instance; }; const RoutingMachine = createControlComponent(createLayer); useEffect(() => { if (mounted.current) { let routeInfo = document.querySelectorAll('tr') console.log(routeInfo) // array with 0 elements } return () => { mounted.current = false; } }, [mounted]); return <RoutingMachine /> };
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar referencias compatibles con el folleto, consulte esta Referencia

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!