πŸ› fix: Fix svg id

This commit is contained in:
canisminor1990
2026-04-08 20:14:21 +08:00
parent 19902babd2
commit 84c15e9579
2 changed files with 14 additions and 12 deletions
+7 -6
View File
@@ -1,8 +1,9 @@
import { kebabCase } from 'es-toolkit';
import { useMemo } from 'react';
import { useId, useMemo } from 'react';
export const useFillId = (namespace: string) => {
const id = `lobe-icons-${kebabCase(namespace)}-fill`;
const uniqueId = useId();
const id = `lobe-icons-${kebabCase(namespace)}-fill-${uniqueId}`;
return useMemo(
() => ({
fill: `url(#${id})`,
@@ -13,14 +14,14 @@ export const useFillId = (namespace: string) => {
};
export const useFillIds = (namespace: string, length: number) => {
const uniqueId = useId();
return useMemo(() => {
const ids = Array.from({ length }, (_, i) => {
const id = `lobe-icons-${kebabCase(namespace)}-fill-${i}`;
return Array.from({ length }, () => {
const id = `lobe-icons-${kebabCase(namespace)}-fill-${uniqueId}`;
return {
fill: `url(#${id})`,
id,
};
});
return ids;
}, [namespace, length]);
}, [namespace, length, uniqueId]);
};
+7 -6
View File
@@ -1,8 +1,9 @@
import { kebabCase } from 'es-toolkit';
import { useMemo } from 'react';
import { useId, useMemo } from 'react';
export const useFillId = (namespace: string) => {
const id = `lobe-icons-${kebabCase(namespace)}-fill`;
const uniqueId = useId();
const id = `lobe-icons-${kebabCase(namespace)}-fill-${uniqueId}`;
return useMemo(
() => ({
fill: `url(#${id})`,
@@ -13,14 +14,14 @@ export const useFillId = (namespace: string) => {
};
export const useFillIds = (namespace: string, length: number) => {
const uniqueId = useId();
return useMemo(() => {
const ids = Array.from({ length }, (_, i) => {
const id = `lobe-icons-${kebabCase(namespace)}-fill-${i}`;
return Array.from({ length }, () => {
const id = `lobe-icons-${kebabCase(namespace)}-fill-${uniqueId}`;
return {
fill: `url(#${id})`,
id,
};
});
return ids;
}, [namespace, length]);
}, [namespace, length, uniqueId]);
};