From e6ef73fccdc6341a30e664231519a3a8b8ef7f00 Mon Sep 17 00:00:00 2001 From: GuillaumeKESTEMAN Date: Wed, 3 Jan 2024 14:41:14 +0100 Subject: [PATCH] fix(collapse): stop to generate id at each rerender --- packages/collapse/src/CollapseCard.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/collapse/src/CollapseCard.tsx b/packages/collapse/src/CollapseCard.tsx index ae9fea236..374d7f8ab 100644 --- a/packages/collapse/src/CollapseCard.tsx +++ b/packages/collapse/src/CollapseCard.tsx @@ -1,10 +1,9 @@ -import React from 'react'; - import { Constants, getComponentClassName, - useId, + useId as getId, } from '@axa-fr/react-toolkit-core'; +import React, { useMemo } from 'react'; import Body, { BodyProps } from './Body'; import Header, { HeaderProps, HeaderToggleElement } from './Header'; @@ -32,7 +31,7 @@ const CollapseCard = ({ index, onToggle, }: CollapseProps) => { - const headerId = useId(id); + const headerId = useMemo(() => getId(id), [id]); const [open, setOpen] = React.useState(isOpen); React.useEffect(() => {