Skip to content

Commit 46512af

Browse files
committed
fix: add useEffect to reset selected chips when defaultValues change
1 parent 47158ef commit 46512af

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/components/Elements/ChipsSet/ChipsSet.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import clsx from 'clsx'
2-
import { useState } from 'react'
2+
import { useEffect, useState } from 'react'
33
import { IoIosClose } from 'react-icons/io'
44
import { Option } from 'src/types'
55
import './chipset.css'
@@ -48,6 +48,10 @@ export const ChipsSet = ({
4848
}: ChipsSetProps) => {
4949
const [selectedChips, setSelectedChips] = useState<string[] | undefined>(defaultValues || [])
5050

51+
useEffect(() => {
52+
setSelectedChips(defaultValues || [])
53+
}, [defaultValues])
54+
5155
const onSelect = (option: Option) => {
5256
if (selectedChips?.some((chipValue) => chipValue === option.value)) {
5357
if (!canSelectMultiple) {

0 commit comments

Comments
 (0)