Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda