Memoize context value (#3786)
parent
31cb3e5422
commit
181e61bedb
|
@ -34,10 +34,17 @@ export function createPortalGroup() {
|
||||||
setOutlet(<>{Object.values(map.current)}</>)
|
setOutlet(<>{Object.values(map.current)}</>)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const contextValue = React.useMemo(
|
||||||
|
() => ({
|
||||||
|
outlet,
|
||||||
|
append,
|
||||||
|
remove,
|
||||||
|
}),
|
||||||
|
[outlet, append, remove],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Context.Provider value={{outlet, append, remove}}>
|
<Context.Provider value={contextValue}>{props.children}</Context.Provider>
|
||||||
{props.children}
|
|
||||||
</Context.Provider>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {InterpretedLabelValueDefinition, AppBskyLabelerDefs} from '@atproto/api'
|
import {AppBskyLabelerDefs, InterpretedLabelValueDefinition} from '@atproto/api'
|
||||||
|
|
||||||
import {useLabelDefinitionsQuery} from '../queries/preferences'
|
import {useLabelDefinitionsQuery} from '../queries/preferences'
|
||||||
|
|
||||||
interface StateContext {
|
interface StateContext {
|
||||||
|
@ -13,10 +14,7 @@ const stateContext = React.createContext<StateContext>({
|
||||||
})
|
})
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const {labelDefs, labelers} = useLabelDefinitionsQuery()
|
const state = useLabelDefinitionsQuery()
|
||||||
|
|
||||||
const state = {labelDefs, labelers}
|
|
||||||
|
|
||||||
return <stateContext.Provider value={state}>{children}</stateContext.Provider>
|
return <stateContext.Provider value={state}>{children}</stateContext.Provider>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue