refactor(dropdownComponent): add useEffect hook to update internalValue when value prop changes to avoid stale data

This commit is contained in:
anovazzi1 2023-06-23 17:28:33 -03:00
commit fc17bc541b

View file

@ -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 (
<>