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

148
Visualizações
Does anyone know why my react map gl is not working

I wanted to know if react typescript was good so I was trying it out. I am running into problems I've never had.

here is my code

function Map() {
  const [viewport, setViewport] = useState({
    width: 400,
    height: 400,
    latitude: 37.7577,
    longitude: -122.4376,
    zoom: 8
  });

  return (
    <ReactMapGL
      {...viewport}
        mapboxApiAccessToken="API key here"
      onViewportChange={(viewport: any) => setViewport(viewport)}
    />
  );
}

This is the error I get

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
▶ 2 stack frames were collapsed.
(anonymous function)
C:/Users/User/Drive/Coding/src/components/interactive-map.js:287
  284 | 
  285 | /* eslint-disable max-statements */
  286 | const InteractiveMap = forwardRef((props, ref) => {
> 287 |   const parentContext = useContext(MapContext);
  288 |   const controller = useMemo(() => props.controller || new MapController(), []);
  289 |   const eventManager = useMemo(
  290 |     () =>

I'm not sure what the cause could be so if you need any more information please ask.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you go to https://reactjs.org/link/invalid-hook-call, you can read

Do not call [hooks] in event handlers.

And that is what you are doing...

about 4 years ago · Juan Pablo Isaza Relatório

0

The problem here is not with react-map-gl, is with the way you're using hooks. Hooks can only be used directly inside function components, because of the way react sort and call them (using arrays) you can read more about that on the official website of React.

about 4 years ago · Juan Pablo Isaza 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