From 181e61bedb21003921fa21f6e8b86baf918d62bf Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 May 2024 05:35:52 +0100 Subject: [PATCH] Memoize context value (#3786) --- src/components/Portal.tsx | 13 ++++++++++--- src/state/preferences/label-defs.tsx | 8 +++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/Portal.tsx b/src/components/Portal.tsx index d696f986..03b397b2 100644 --- a/src/components/Portal.tsx +++ b/src/components/Portal.tsx @@ -34,10 +34,17 @@ export function createPortalGroup() { setOutlet(<>{Object.values(map.current)}) }, []) + const contextValue = React.useMemo( + () => ({ + outlet, + append, + remove, + }), + [outlet, append, remove], + ) + return ( - - {props.children} - + {props.children} ) } diff --git a/src/state/preferences/label-defs.tsx b/src/state/preferences/label-defs.tsx index d60f8ccb..e24a1144 100644 --- a/src/state/preferences/label-defs.tsx +++ b/src/state/preferences/label-defs.tsx @@ -1,5 +1,6 @@ import React from 'react' -import {InterpretedLabelValueDefinition, AppBskyLabelerDefs} from '@atproto/api' +import {AppBskyLabelerDefs, InterpretedLabelValueDefinition} from '@atproto/api' + import {useLabelDefinitionsQuery} from '../queries/preferences' interface StateContext { @@ -13,10 +14,7 @@ const stateContext = React.createContext({ }) export function Provider({children}: React.PropsWithChildren<{}>) { - const {labelDefs, labelers} = useLabelDefinitionsQuery() - - const state = {labelDefs, labelers} - + const state = useLabelDefinitionsQuery() return {children} }