Skip to content

Commit

Permalink
Merge branch 'use-debounce' of https://www.github.com/openmrs/openmrs…
Browse files Browse the repository at this point in the history
…-esm-core into use-debounce
  • Loading branch information
vasharma05 committed Sep 6, 2023
2 parents 8de8f4b + d14575d commit e57e93d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/framework/esm-react-utils/src/useDebounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@ import { useEffect, useState } from "react";
* This hook debounces a state variable. That state variable can then be used as the
* value of a controlled input, while the return value of this hook is used for making
* a request.
*
*
* @example
*
* ```tsx
* import { useDebounce } from "@openmrs/esm-react-utils";
*
*
* function MyComponent() {
* const [searchTerm, setSearchTerm] = useState('');
* const debouncedSearchTerm = useDebounce(searchTerm);
* const swrResult = useSWR(`/api/search?q=${debouncedSearchTerm}`)
*
* const swrResult = useSWR(`/api/search?q=${debouncedSearchTerm}`)
*
* return (
* <Search
labelText={t('search', 'Search')}
onChange={(e) => setSearchTerm(e.target.value)}
value={searchTerm}
/>
* labelText={t('search', 'Search')}
* onChange={(e) => setSearchTerm(e.target.value)}
* value={searchTerm}
* />
* )
* }
*
* ```
*
*
* @param value: The value that will be used to set `debounceValue`
* @param delay number = 300: The number of milliseconds to wait before updating `debounceValue`
* @returns debounceValue: The debounced value
Expand Down

0 comments on commit e57e93d

Please sign in to comment.