Memoize usePalette (#2201)

zio/stable
dan 2023-12-13 07:09:07 +00:00 committed by GitHub
parent b1f9454f1d
commit 0e3218db7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 34 deletions

View File

@ -1,3 +1,4 @@
import {useMemo} from 'react'
import {TextStyle, ViewStyle} from 'react-native' import {TextStyle, ViewStyle} from 'react-native'
import {useTheme, PaletteColorName, PaletteColor} from '../ThemeContext' import {useTheme, PaletteColorName, PaletteColor} from '../ThemeContext'
@ -15,7 +16,9 @@ export interface UsePaletteValue {
icon: TextStyle icon: TextStyle
} }
export function usePalette(color: PaletteColorName): UsePaletteValue { export function usePalette(color: PaletteColorName): UsePaletteValue {
const palette = useTheme().palette[color] const theme = useTheme()
return useMemo(() => {
const palette = theme.palette[color]
return { return {
colors: palette, colors: palette,
view: { view: {
@ -49,4 +52,5 @@ export function usePalette(color: PaletteColorName): UsePaletteValue {
color: palette.icon, color: palette.icon,
}, },
} }
}, [theme, color])
} }