-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move label defs into a context to reduce recomputes
- Loading branch information
Showing
8 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import {InterpretedLabelValueDefinition, AppBskyLabelerDefs} from '@atproto/api' | ||
import {useLabelDefinitionsQuery} from '../queries/preferences' | ||
|
||
interface StateContext { | ||
labelDefs: Record<string, InterpretedLabelValueDefinition[]> | ||
labelers: AppBskyLabelerDefs.LabelerViewDetailed[] | ||
} | ||
|
||
const stateContext = React.createContext<StateContext>({ | ||
labelDefs: {}, | ||
labelers: [], | ||
}) | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
const {labelDefs, labelers} = useLabelDefinitionsQuery() | ||
|
||
const state = {labelDefs, labelers} | ||
|
||
return <stateContext.Provider value={state}>{children}</stateContext.Provider> | ||
} | ||
|
||
export function useLabelDefinitions() { | ||
return React.useContext(stateContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters