Optimise editor component

This commit is contained in:
Benji Grant 2023-06-09 01:58:02 +10:00
parent f72204c796
commit 30d50b0b0a
4 changed files with 37 additions and 55 deletions

View file

@ -1,13 +1,14 @@
import { useMemo } from 'react'
import { createPalette } from 'hue-map'
import { useStore } from '/src/stores'
import useSettingsStore from '/src/stores/settingsStore'
export const usePalette = (min: number, max: number) => {
export const usePalette = (steps: number) => {
const colormap = useStore(useSettingsStore, state => state.colormap)
return createPalette({
return useMemo(() => createPalette({
map: (colormap === undefined || colormap === 'crabfit') ? [[0, [247, 158, 0, 0]], [1, [247, 158, 0, 255]]] : colormap,
steps: Math.max((max - min) + 1, 2),
}).format()
steps,
}).format(), [steps])
}