From f77f7c120a00e65dbed5290f1e474108a1cfb950 Mon Sep 17 00:00:00 2001 From: Andre H Date: Thu, 29 Feb 2024 08:52:26 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore:=20follow=20select=20chang?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/shared/UserSelect/UserSelect.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/frontend/src/components/shared/UserSelect/UserSelect.tsx b/packages/frontend/src/components/shared/UserSelect/UserSelect.tsx index 7bfca072..eaae61d1 100644 --- a/packages/frontend/src/components/shared/UserSelect/UserSelect.tsx +++ b/packages/frontend/src/components/shared/UserSelect/UserSelect.tsx @@ -1,7 +1,6 @@ import React, { useState, ComponentPropsWithoutRef, - useCallback, useRef, useEffect, } from 'react'; @@ -34,7 +33,7 @@ export const UserSelect = ({ options, value }: UserSelectProps) => { const navigate = useNavigate(); const [selectedItem, setSelectedItem] = useState( - null, + (value as UserSelectOption) || null, ); const [dropdownOpen, setDropdownOpen] = useState(false); const [dropdownPosition, setDropdownPosition] = useState<'top' | 'bottom'>( @@ -75,10 +74,8 @@ export const UserSelect = ({ options, value }: UserSelectProps) => { navigate(`/${selectedItem?.value}`); }; - const isSelected = useCallback( - (item: UserSelectOption) => selectedItem?.value === item.value, - [selectedItem], - ); + const isSelected = (item: UserSelectOption) => + selectedItem?.value === item.value; const { isOpen, getMenuProps, highlightedIndex, getItemProps, openMenu } = useCombobox({ @@ -94,7 +91,7 @@ export const UserSelect = ({ options, value }: UserSelectProps) => { onIsOpenChange: ({ isOpen }) => { setDropdownOpen(isOpen ?? false); }, - selectedItem: selectedItem, + selectedItem: value || null, itemToString: (item) => (item ? item.label : ''), });