Skip to content

Commit

Permalink
adding a 3 second debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
Courey committed Sep 20, 2024
1 parent b7229e2 commit 8a67744
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/routes/synonyms.$synonymId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ export default function () {
})

useEffect(() => {
if (input.length >= 3)
submit({ query: input }, { preventScrollReset: true })
const delayDebounceFn = setTimeout(() => {

Check warning on line 119 in app/routes/synonyms.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.$synonymId.tsx#L118-L119

Added lines #L118 - L119 were not covered by tests
if (input.length >= 3)
submit({ query: input }, { preventScrollReset: true })

Check warning on line 121 in app/routes/synonyms.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.$synonymId.tsx#L121

Added line #L121 was not covered by tests
}, 3000)

return () => clearTimeout(delayDebounceFn)

Check warning on line 124 in app/routes/synonyms.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.$synonymId.tsx#L124

Added line #L124 was not covered by tests
}, [input, submit])

return (
Expand Down
8 changes: 6 additions & 2 deletions app/routes/synonyms.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ export default function () {
const uniqueOptions = Array.from(new Set(options)) as string[]

Check warning on line 70 in app/routes/synonyms.new.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.new.tsx#L69-L70

Added lines #L69 - L70 were not covered by tests

useEffect(() => {
if (input.length >= 3)
submit({ query: input }, { preventScrollReset: true })
const delayDebounceFn = setTimeout(() => {

Check warning on line 73 in app/routes/synonyms.new.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.new.tsx#L72-L73

Added lines #L72 - L73 were not covered by tests
if (input.length >= 3)
submit({ query: input }, { preventScrollReset: true })

Check warning on line 75 in app/routes/synonyms.new.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.new.tsx#L75

Added line #L75 was not covered by tests
}, 3000)

return () => clearTimeout(delayDebounceFn)

Check warning on line 78 in app/routes/synonyms.new.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.new.tsx#L78

Added line #L78 was not covered by tests
}, [input, submit])

return (

Check warning on line 81 in app/routes/synonyms.new.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms.new.tsx#L81

Added line #L81 was not covered by tests
Expand Down

0 comments on commit 8a67744

Please sign in to comment.