Skip to content

Commit

Permalink
add check for min length
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed May 9, 2024
1 parent 3ab217e commit 1f37df7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions site/src/examples/combo-box/ServerSideData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const fetcher = async (url: string, filter: string) => {

export const ServerSideData = (): ReactElement => {
const [value, setValue] = useState("");
const minLengthIsMet = value.length > 2;
const { data, isLoading } = useSWR<string[]>(
value.length > 2 ? `/example-data/states.json?s=${value}` : null,
minLengthIsMet ? `/example-data/states.json?s=${value}` : null,
(url: string) => fetcher(url, value),
{
fallbackData: [],
Expand Down Expand Up @@ -63,7 +64,7 @@ export const ServerSideData = (): ReactElement => {
{!loading && hasResults
? data?.map((state) => <Option value={state} key={state} />)
: null}
{!loading && !hasResults ? (
{!loading && !hasResults && minLengthIsMet ? (
<div
className={styles.statusOption}
role="option"
Expand Down

0 comments on commit 1f37df7

Please sign in to comment.