Memoize usePalette (#2201)
parent
b1f9454f1d
commit
0e3218db7d
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue