From 92c0a8b4f00c4c4577d9a4ba5a300fba13200ad7 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 3 Jan 2024 09:49:48 +0800 Subject: [PATCH] Test memoize svg icon --- src/components/icon.jsx | 52 +++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/components/icon.jsx b/src/components/icon.jsx index e444cd4b..3a2aea25 100644 --- a/src/components/icon.jsx +++ b/src/components/icon.jsx @@ -1,3 +1,4 @@ +import moize from 'moize'; import { useEffect, useRef, useState } from 'preact/hooks'; const SIZES = { @@ -110,6 +111,29 @@ export const ICONS = { const ICONDATA = {}; +// Memoize the dangerouslySetInnerHTML of the SVGs +const SVGICon = moize( + function ({ size, width, height, body, rotate, flip }) { + return ( + + ); + }, + { + isShallowEqual: true, + maxSize: Object.keys(ICONS).length, + }, +); + function Icon({ icon, size = 'm', @@ -150,16 +174,24 @@ function Icon({ }} > {iconData && ( - + )}