Skip to content

Commit f3a612f

Browse files
authored
Fixes VanillaSelect requiring two renders to update (#121)
I was having issues with the VanillaSelect not updating its state when something update the metadatacache I've swapped it to use useControlledState like all the other components. Fixed it for me.
1 parent a1b96f7 commit f3a612f

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/api/ui/basics.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,14 @@ export function VanillaSelect(
169169
} & React.ComponentProps<"select">
170170
) {
171171
const { className, options = [], value, defaultValue, onValueChange, ...forwardingProps } = props;
172-
const [selectedValue, setSelectedValue] = React.useState(value ?? defaultValue ?? "");
173-
174-
React.useEffect(() => {
175-
if (typeof value === "string") setSelectedValue(value);
176-
}, [value]);
172+
const [selectedValue, setSelectedValue] = useControlledState(defaultValue ?? "", value, onValueChange);
177173

178174
return (
179175
<select
180176
className={combineClasses("dc-select dropdown", className)}
181177
value={selectedValue}
182178
onChange={(e) => {
183179
setSelectedValue(e.currentTarget.value);
184-
onValueChange && onValueChange(e.currentTarget.value);
185180
}}
186181
{...forwardingProps}
187182
>

0 commit comments

Comments
 (0)