Optimize rerenders

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
        <script crossorigin src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
        <script crossorigin src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
        <script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
        <!-- To make the map appear, you must add your apikey -->
        <script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>

        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="../variables.ts"
        ></script>
        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="./common.ts"
        ></script>
        <script data-plugins="transform-modules-umd" data-presets="react, typescript" type="text/babel">
            import {CITY_1, CITY_2} from '../variables';
            import type {LngLat} from '@yandex/ymaps3-types';
            
            window.map = null;
            
            main();
            async function main() {
                // For each object in the JS API, there is a React counterpart
                // To use the React version of the API, include the module @yandex/ymaps3-reactify
                const [ymaps3React] = await Promise.all([ymaps3.import('@yandex/ymaps3-reactify'), ymaps3.ready]);
                const reactify = ymaps3React.reactify.bindTo(React, ReactDOM);
                const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapControls, YMapControlButton} =
                    reactify.module(ymaps3);
            
                const {YMapZoomControl, YMapDefaultMarker} = reactify.module(
                    await ymaps3.import('@yandex/ymaps3-default-ui-theme')
                );
            
                /** Returns `coords` shifted by `diff`. Always returns new array to illustrate rerender related problems. */
                function shift(coords: LngLat, diff: LngLat): LngLat {
                    return [coords[0] + diff[0], coords[1] + diff[1]];
                }
            
                function App() {
                    const [location, setLocation] = React.useState<{center: LngLat; zoom: number; duration?: number}>(
                        CITY_1.location
                    );
                    const [counter, setCounter] = React.useState(0);
            
                    return (
                        /* Initialize the map and pass initialization parameters */
                        <YMap location={reactify.useDefault(location, [location])} ref={(x) => (map = x)}>
                            {/* Add a map scheme layer */}
                            <YMapDefaultSchemeLayer />
                            <YMapDefaultFeaturesLayer />
            
                            {/* YMapZoomControl sets map's `location`. Our state `location` doesn't know anything about it */}
                            <YMapControls position="right">
                                <YMapZoomControl />
                            </YMapControls>
            
                            <YMapControls position="top">
                                {/* Set map location with animation */}
                                <YMapControlButton
                                    text={CITY_1.name}
                                    onClick={() => setLocation({...CITY_1.location, duration: 1000})}
                                />
                                {/* Set map location. Create a copy of object to trigger `update` */}
                                <YMapControlButton text={CITY_2.name} onClick={() => setLocation({...CITY_2.location})} />
                                {/* Trigger rerender */}
                                <YMapControlButton text={`Rerender! ${counter}`} onClick={() => setCounter((x) => x + 1)} />
                            </YMapControls>
            
                            {/* Any rerender will update coordinates */}
                            <YMapDefaultMarker
                                size="normal"
                                coordinates={shift(location.center, [-0.05, -0.05])}
                                draggable
                                title="without useDefault"
                                color="pink"
                            />
                            {/* Only rerenders with changed `location.center` will update coordinates */}
                            <YMapDefaultMarker
                                size="normal"
                                coordinates={reactify.useDefault(shift(location.center, [0.05, 0.05]), [location.center])}
                                draggable
                                title="with useDefault"
                            />
                        </YMap>
                    );
                }
            
                ReactDOM.render(
                    <React.StrictMode>
                        <App />
                    </React.StrictMode>,
                    document.getElementById('app')
                );
            }
        </script>

        <style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; }  </style>
        <link rel="stylesheet" href="./common.css" />
    </head>
    <body>
        <div id="app"></div>
    </body>
</html>
import type { LngLat } from '@yandex/ymaps3-types';

export const CITY_1 = {
    name: 'Москва',
    location: {
        center: [37.623082, 55.75254] as LngLat,
        zoom: 9
    }
};

export const CITY_2 = {
    name: 'Санкт-Петербург',
    location: {
        center: [30.30, 59.93] as LngLat,
        zoom: 10
    }
};
ymaps3.ready.then(() => {
    ymaps3.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', ['@yandex/ymaps3-default-ui-theme@0.0'])
});