Idem with <Tile/>

This commit is contained in:
Eric van der Vlist 2022-10-18 16:57:18 +02:00
parent a7f78e0fa9
commit 016f99daf6
1 changed files with 8 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import react, { useEffect, useRef } from 'react';
import react, { memo, useEffect, useRef } from 'react';
import { isEqual } from 'lodash';
export interface TileProperties {
/** The image's source URL */
@ -20,13 +21,13 @@ export interface TileProperties {
* They are designed to be part of {@link components/map/TiledLayer!TiledLayer} components in SVG `<g/>` elements
* in which the unit is the tile size. In this coordinate system their size is thus always equal to 1.
*/
export const Tile: react.FC<TileProperties> = (props: TileProperties) => {
export const Tile: react.FC<TileProperties> = memo((props: TileProperties) => {
const g = useRef<SVGGElement>(null);
const timeout = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
console.log(`Rendering tile: ${props.href}`);
useEffect(() => {
const loadImage = async () => {
console.log(`Pre loading: ${props.href}`);
@ -54,6 +55,6 @@ export const Tile: react.FC<TileProperties> = (props: TileProperties) => {
}, [props.href]);
return <g ref={g} />;
};
}, isEqual);
export default Tile;