Closed Wimmind closed 3 years ago
`import React, { useState } from "react"; import { YMaps, Map } from "react-yandex-maps";
const YandexMap = () => { const [coords, setCoords] = useState({ lat: 56.8498, long: 53.2045, });
const getCoords = (ymaps) => { ymaps.geocode("Екатеринбург,Банковский переулок, 1").then((result) => { const newCoords = result.geoObjects.get(0).geometry.getCoordinates(); setCoords({ lat: newCoords[0], long: newCoords[1], }); console.log(newCoords); }); };
return ( <YMaps query={{ apikey: .... }}> <Map onLoad={(ymaps) => getCoords(ymaps)} modules={["geocode"]} width="100%" height="500px" /> ); };
export default YandexMap;`
ошибка:
Извиняюсь, не указал state в пропсах map
`import React, { useState } from "react"; import { YMaps, Map } from "react-yandex-maps";
const YandexMap = () => { const [coords, setCoords] = useState({ lat: 56.8498, long: 53.2045, });
const getCoords = (ymaps) => { ymaps.geocode("Екатеринбург,Банковский переулок, 1").then((result) => { const newCoords = result.geoObjects.get(0).geometry.getCoordinates(); setCoords({ lat: newCoords[0], long: newCoords[1], }); console.log(newCoords); }); };
return ( <YMaps query={{ apikey: .... }}> <Map onLoad={(ymaps) => getCoords(ymaps)} modules={["geocode"]} width="100%" height="500px" /> ); };
export default YandexMap;`
ошибка: