File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
src/shared/ui/ManagedSelect/hooks/useSearch Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ export * from './useSearch' ;
2+ export * from './types' ;
Original file line number Diff line number Diff line change 1+ /** Interface as Props for hook "useSearch" */
2+ export interface UseSearchProps {
3+ /** Callback on change search input value in Select */
4+ onSearch ?: ( value : string ) => void ;
5+ }
Original file line number Diff line number Diff line change 1+ import { useDebouncedState } from '@shared/hooks' ;
2+
3+ import { SEARCH_VALUE_CHANGE_DELAY , SEARCH_VALUE_DEFAULT } from '../../constants' ;
4+
5+ import { UseSearchProps } from './types' ;
6+
7+ /** Hook for handling search value in Select */
8+ export const useSearch = ( { onSearch = ( ) => undefined } : UseSearchProps ) => {
9+ const {
10+ value : searchValue ,
11+ setValue : setSearchValue ,
12+ setDebouncedValue : setDebouncedSearchValue ,
13+ } = useDebouncedState ( SEARCH_VALUE_DEFAULT , SEARCH_VALUE_CHANGE_DELAY ) ;
14+
15+ const handleSearch = ( value : string ) => {
16+ setDebouncedSearchValue ( value ) ;
17+ onSearch ( value ) ;
18+ } ;
19+
20+ return { searchValue, handleSearch, setSearchValue } ;
21+ } ;
You can’t perform that action at this time.
0 commit comments