mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Add fallback to average color calculation
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { FastAverageColor } from 'fast-average-color';
|
||||
|
||||
export const useFastAverageColor = (
|
||||
src?: string | null,
|
||||
aglorithm?: 'dominant' | 'simple' | 'sqrt',
|
||||
) => {
|
||||
const isMountedRef = useRef<boolean | null>(null);
|
||||
const [color, setColor] = useState<string | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -27,6 +28,10 @@ export const useFastAverageColor = (
|
||||
console.log('Error fetching average color', e);
|
||||
return setColor('rgba(0, 0, 0, 0)');
|
||||
});
|
||||
} else if (isMountedRef.current) {
|
||||
return setColor('var(--placeholder-bg)');
|
||||
} else {
|
||||
isMountedRef.current = true;
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user