From 08f1529a12e1c11cafc82e06731cf7b65e2f1161 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Sun, 1 Sep 2024 17:11:50 -0700 Subject: [PATCH] Hoist empty styles static constant --- packages/styling/src/useStyles.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/styling/src/useStyles.ts b/packages/styling/src/useStyles.ts index c2ee5635..75c2688d 100644 --- a/packages/styling/src/useStyles.ts +++ b/packages/styling/src/useStyles.ts @@ -9,9 +9,11 @@ type StyleCache = Map< const styleCache: StyleCache = new Map(); +const EMPTY_STYLES_ITEM = { href: '', referenceCount: 0, styles: '' }; + export function useStyles(styles: string, initialHref?: string) { const [stylesItem, setStylesItem] = useState(() => { - if (!styles) return { href: '', referenceCount: 0, styles: '' }; + if (!styles) return EMPTY_STYLES_ITEM; const key = initialHref ?? styles; let item = styleCache.get(key);