Closed martins4duarte closed 2 months ago
Hi, check that you use last version of MultiSelect component with that code inside of it:
/** rest of the component's code */
const [selectedValues, setSelectedValues] = React.useState<string[]>(defaultValue);
const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);
const [isAnimating, setIsAnimating] = React.useState(false);
React.useEffect(() => {
setSelectedValues(defaultValue);
}, [defaultValue]);
/** rest of the component's code */
Yes, as in documentation
try to pass an empty array here:
const form = useForm<Example>({
resolver: zodResolver(exampleSchema),
defaultValues: {
example: []
},
});
same
I'm also having the same issue.
React.useEffect(() => { console.log("useEffect triggered with defaultValue:", defaultValue); setSelectedValues(defaultValue); }, [defaultValue]);
Is this part necessary?
when the defaultValue is not passed from the parent, then it is into a infinite loop.
@rmidhunk as a temporary solution, i just removed this useEffect part and transform defaultValue parameter into a optional, is working well.
Fixed
Hello @sersavan !
first of all, thanks for share your component!
im trying to use it without defaultValues, but have useEffect to update state on first render and it is causing a error when defaultValues doesnt exist, causing error:
Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
If i try to pass a empty string, i have empty component on UI as image below.