refactor(dropdownComponent): add useEffect hook to update internalValue when value prop changes to avoid stale data
This commit is contained in:
parent
d06e8aa517
commit
fc17bc541b
1 changed files with 4 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { Listbox, Transition } from "@headlessui/react";
|
||||
import { ChevronUpDownIcon, CheckIcon } from "@heroicons/react/24/outline";
|
||||
import { Fragment, useState } from "react";
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import { DropDownComponentType } from "../../types/components";
|
||||
import { classNames } from "../../utils";
|
||||
import { INPUT_STYLE } from "../../constants";
|
||||
|
|
@ -15,6 +15,9 @@ export default function Dropdown({
|
|||
let [internalValue, setInternalValue] = useState(
|
||||
value === "" || !value ? "Choose an option" : value
|
||||
);
|
||||
useEffect(()=>{
|
||||
setInternalValue(value === "" || !value ? "Choose an option" : value)
|
||||
},[value])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue