I'm trying to add a source for my mapboxgl map which I am writing in React with hooks and TypeScript.
export default function App() {
const mapContainer = React.useRef<any>(null);
const map = React.useRef<any>(null);
const [lng, setLng] = React.useState(-74.0632);
const [lat, setLat] = React.useState(40.7346);
const [zoom, setZoom] = React.useState(12);
React.useEffect(() => {
if (map.current) return; // initialize map only once
map.current = new mapboxgl.Map({
container: mapContainer.current,
style: 'mapbox://styles/mapbox/streets-v11',
center: [lng, lat],
zoom: zoom
});
map.addSource('property-data', {
type: 'geojson',
data: 'path/to/data.geojson'
});
});
I am encountering the following error:
Property 'addSource' does not exist on type 'MutableRefObject'
What type then should I use if not any?