fix admin save state architecture
This commit is contained in:
@@ -5,6 +5,7 @@ import * as SelectPrimitive from "@radix-ui/react-select";
|
||||
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useHiddenInputSync } from "@/components/ui/use-hidden-input-sync";
|
||||
|
||||
type SelectProps = React.ComponentPropsWithoutRef<typeof SelectPrimitive.Root> & {
|
||||
name?: string;
|
||||
@@ -23,10 +24,11 @@ function Select({
|
||||
const [internalValue, setInternalValue] = React.useState(defaultValue ?? "");
|
||||
const isControlled = value !== undefined;
|
||||
const currentValue = (isControlled ? value : internalValue) as string;
|
||||
const hiddenInputRef = useHiddenInputSync(currentValue);
|
||||
|
||||
return (
|
||||
<>
|
||||
{name ? <input type="hidden" name={name} value={currentValue} required={required} /> : null}
|
||||
{name ? <input ref={hiddenInputRef} type="hidden" name={name} value={currentValue} required={required} /> : null}
|
||||
<SelectPrimitive.Root
|
||||
value={value}
|
||||
defaultValue={defaultValue}
|
||||
|
||||
Reference in New Issue
Block a user