Skip to content

Commit ec3b71d

Browse files
authored
fix: error complains clickedItem is undefined (#126)
1 parent 5347a4d commit ec3b71d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/src/components/Toggle.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const Toggle: React.FunctionComponent<Props> = ({
5959

6060
useEffect(() => {
6161
if (
62+
clickedItem &&
6263
clickedItem.scroll &&
6364
clickedItem.state &&
6465
clickedItem.label === label
@@ -80,15 +81,15 @@ export const Toggle: React.FunctionComponent<Props> = ({
8081

8182
// for collapsing items in container when container will collapse
8283
if (
83-
!clickedItem.state &&
84+
!(clickedItem && clickedItem.state) &&
8485
ITEM_LABELS_VALUES.toString().includes(label) &&
8586
clickedItem.label === inContainer(label as ITEM_LABELS)
8687
) {
8788
setExpanded(false);
8889
return;
8990
}
9091

91-
if (!expanded && clickedItem.state && label) {
92+
if (!expanded && clickedItem && clickedItem.state && label) {
9293
// for container when hash will change
9394
if (
9495
clickedItem.label === label &&

0 commit comments

Comments
 (0)