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

127
Views
¿Cómo pasar el estado al controlador del componente secundario?

El componente GeoJson tiene una función onEachFeature que llama a un controlador, en este caso es createPopup .

<GeoJSON data={covidGeoJSON} onEachFeature={createPopup}></GeoJSON>

Dentro del controlador createPopup , ¿cómo puedo acceder a los estados definidos dentro del componente CovidMap?

 import React, { useState } from 'react' import { MapContainer, GeoJSON } from 'react-leaflet' import 'leaflet/dist/leaflet.css' CovidMap = ({ covidGeoJSON, styles }) => { const showCords = (e) => { console.log(e.latlng); } const createPopup = (state, layer) => { layer.on({ mouseover: showCords, }); layer.bindPopup(state.properties.NAME); } const [range, setRange] = useState([]); return ( <div> <MapContainer style={{ height: '90vh', width: '100vw' }} center={[39.162497380360634, -94.83672007881789]} zoom={5}> <GeoJSON data={covidGeoJSON} onEachFeature={createPopup}></GeoJSON> </MapContainer> </div> ) } export default CovidMap
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debería poder hacer referencia al estado desde createPopup . Cree y use variables de estado dentro de CovidMap usando el useState :

 const CovidMap = () => { ... const [properties, setProperties] = useState({}); // Defined BEFORE handler const [layer, setLayer] = useState({}); // Defined BEFORE handler const createPopup = () => { layer.on({ mouseover: showCords, }); layer.bindPopup(properties.NAME); } ... }
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!