Quería saber si reaccionar mecanografiado era bueno, así que lo estaba probando. Me estoy encontrando con problemas que nunca he tenido.
aquí está mi código
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)} /> ); }este es el error que me sale
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 | () =>No estoy seguro de cuál podría ser la causa, así que si necesita más información, por favor pregunte.
Si va a https://reactjs.org/link/invalid-hook-call , puede leer
No llame a [ganchos] en los controladores de eventos.
Y eso es lo que estás haciendo...
El problema aquí no es con react-map-gl , es con la forma en que estás usando ganchos. Los ganchos solo se pueden usar directamente dentro de los componentes de la función, debido a la forma en que reaccionan los ordena y los llama (usando matrices), puede leer más sobre eso en el sitio web oficial de React.