Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
How to reload map component when some value changes

I have a component that loads a google map according to the Lat and Lng passed, but when I change this value, I need the map to be rendered on the screen

  const [getLat, setGetLat] = useState(geoLocation.mapsLat);
  const [getLng, setGetLng] = useState(geoLocation.mapsLng);

  const loadMap = getLat && getLng;


useEffect((previousValue) => {
      const { zipCode } = formValues;

      if (zipCode !== previousValue) {
        console.log('need reload the map');
      }
    },
    [ ]
  );

How do I render this fixed part of my code when it happens in console.log?

  return (
    {loadMap && (
        <div className="container">
          <label>Map</label>
          <Map lat={getLat} lng={getLng} handleClick={handleSubmit} />
        </div>
      )}
  )
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

  const [getLat, setGetLat] = useState(geoLocation.mapsLat);
  const [getLng, setGetLng] = useState(geoLocation.mapsLng);


useEffect((previousValue) => {
      const { zipCode } = formValues;
      setGetLat(geoLocation.mapsLat);
      setGetLng(geoLocation.mapsLng);
   },[geoLocation.mapsLat,geoLocation.mapsLng]);
  return (
    {getLat && getLng && (
        <div className="container">
          <label>Map</label>
          <Map lat={getLat} lng={getLng} handleClick={handleSubmit} />
        </div>
      )}
  )

The above code must resolve your problem. whenever your zipCode value changes the component will rerender and your ui would be updated.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda