implemented useMemo for loading state

This commit is contained in:
rgrgogu
2026-07-16 03:22:38 +08:00
parent dc992c7f77
commit ac2ba33e24
+14 -8
View File
@@ -64,6 +64,8 @@ const CountrySelect = ({
const [searchValue, setSearchValue] = React.useState("") const [searchValue, setSearchValue] = React.useState("")
const [isOpen, setIsOpen] = React.useState(false) const [isOpen, setIsOpen] = React.useState(false)
const handleSelectComplete = React.useCallback(() => setIsOpen(false), [])
return ( return (
<Popover <Popover
open={isOpen} open={isOpen}
@@ -123,7 +125,7 @@ const CountrySelect = ({
countryName={label} countryName={label}
selectedCountry={selectedCountry} selectedCountry={selectedCountry}
onChange={onChange} onChange={onChange}
onSelectComplete={() => setIsOpen(false)} onSelectComplete={handleSelectComplete}
/> />
) : null, ) : null,
)} )}
@@ -136,23 +138,27 @@ const CountrySelect = ({
) )
} }
const CountrySelectOption = ({ const CountrySelectOption = React.memo(function CountrySelectOption({
country, country,
countryName, countryName,
selectedCountry, selectedCountry,
onChange, onChange,
onSelectComplete, onSelectComplete,
}) => { }) {
const handleSelect = () => { const handleSelect = () => {
onChange(country) onChange(country)
onSelectComplete() onSelectComplete()
} }
return ( return (
<CommandItem className="flex items-center justify-between gap-2" onSelect={handleSelect}> <CommandItem
value={countryName}
className="flex items-center justify-between gap-2"
onSelect={handleSelect}
>
<div className="flex items-center flex-1 gap-2"> <div className="flex items-center flex-1 gap-2">
<FlagComponent country={country} countryName={countryName} /> <FlagComponent country={country} countryName={countryName} />
<span className="text-sm truncate">{countryName}</span> <span className="text-sm w-54 truncate">{countryName}</span>
</div> </div>
<div className="whitespace-nowrap flex min-w-0"> <div className="whitespace-nowrap flex min-w-0">
<span className="text-sm text-foreground/50">{`+${RPNInput.getCountryCallingCode(country)}`}</span> <span className="text-sm text-foreground/50">{`+${RPNInput.getCountryCallingCode(country)}`}</span>
@@ -162,9 +168,9 @@ const CountrySelectOption = ({
</div> </div>
</CommandItem> </CommandItem>
) )
} })
const FlagComponent = ({ country, countryName }) => { const FlagComponent = React.memo(function FlagComponent({ country, countryName }) {
const Flag = flags[country] const Flag = flags[country]
return ( return (
@@ -172,6 +178,6 @@ const FlagComponent = ({ country, countryName }) => {
{Flag && <Flag title={countryName} />} {Flag && <Flag title={countryName} />}
</span> </span>
) )
} })
export { PhoneInput } export { PhoneInput }