gribnoysup / react-yandex-maps

Yandex Maps API bindings for React
MIT License
327 stars 114 forks source link

Как воспользоваться методом findOrganization ? #318

Open AVeselov95 opened 2 years ago

AVeselov95 commented 2 years ago

Беру YMaps провайдер и через withYMaps получаю ymaps (Yandex.Maps API object)

но при попытке вызвать ymaps.findOrganization получаю ошибку ymaps.findOrganization is not a function

пример https://codesandbox.io/s/eager-brahmagupta-p5crh?file=/src/App.js

mmarkelov commented 2 years ago

@AVeselov95 Я не знаю какой частью модуля является этот метод. Работает с подключением полной библиотеки:

import "./styles.css";
import { YMaps, withYMaps } from "react-yandex-maps";

const Button = ({ ymaps }) => {
  const onClick = async () => {
    if (ymaps) {
      const data = await ymaps.findOrganization("1671141286");
      console.log(data);
    }
  };

  return <button onClick={onClick}> get </button>;
};

const ButtonWithYMap = withYMaps(Button, true);

export default function App() {
  return (
    <>
      <YMaps
        query={{
          apikey: "API_KEY",
          lang: "en_RU",
          load: "package.full"
        }}
      >
        <ButtonWithYMap />
      </YMaps>
    </>
  );
}

Также без ключа разработчика скорее всего не заработает