From 80dc1996c173ba892c54adb0b3e5eb0c6525f6bc 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 c2ee563..75c2688 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);