Closed ValeryVS closed 4 years ago
Is it possible with two providers? I tried to do some research, and even be able to reload map, but it's language isn't changed. https://codesandbox.io/s/react-yandex-maps-vector-experiment-nvmgb
https://github.com/gribnoysup/react-yandex-maps/blob/697996e34b920b3de628015954cf87e11d372cbb/src/YMaps.js#L34-L38 here returned api from first loaded provider
Made some further research. Seems like Provider should be able to reload ymaps and reset context, while all components should be able to update itself, when context is updated.
I'm not sure that I want to support it in the library to be honest, but you can force React to completely rerender the Provider component with the key
prop and this will force the re-fetching of the API with the new locale. Here's a code example of this approach:
function App() {
const [lang, setLang] = React.useState("ru_RU");
return (
<>
<button onClick={() => setLang("en_US")}>Toggle language</button>
<YMaps key={lang} query={{ lang }}>
<Map defaultState={{ center: [0, 0], zoom: 5 }} />
</YMaps>
</>
);
}
Now Provider doesn't update script even if another
lang
will be passed to YMaps.It would be good if it will be able to reload api with different language, like there https://tech.yandex.ru/maps/jsbox/2.1/language