From e6d30c291beab09514a994b56c645ff57406fff7 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 25 Nov 2022 00:16:38 -0600 Subject: [PATCH] Add memoization to useBackground --- src/useBackground.tsx | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/useBackground.tsx b/src/useBackground.tsx index 216a80f..c6594a9 100644 --- a/src/useBackground.tsx +++ b/src/useBackground.tsx @@ -47,27 +47,29 @@ const useBackground = ({ setBackground(generateBackground()); }; - const svgWidth = Math.ceil((width ?? 1920) * ratio); - const svgHeight = Math.ceil((height ?? 1080) * ratio); - const noise = ( - - - - - - - - - ); + const noise = useMemo(() => { + const svgWidth = Math.ceil((width ?? 1920) * ratio); + const svgHeight = Math.ceil((height ?? 1080) * ratio); + return ( + + + + + + + + + ); + }, [width, height, ratio]); return { regenerate,