Skip to content

Commit c93b662

Browse files
committed
improve search lag
1 parent 21abec9 commit c93b662

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/react-native-ui/src/Search.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BottomSheetTextInput } from '@gorhom/bottom-sheet';
22
import { styled } from '@storybook/react-native-theming';
33
import type { IFuseOptions } from 'fuse.js';
44
import Fuse from 'fuse.js';
5-
import React, { useCallback, useRef, useState } from 'react';
5+
import React, { useCallback, useDeferredValue, useRef, useState } from 'react';
66
import { TextInput, View } from 'react-native';
77
import { CloseIcon } from './icon/CloseIcon';
88
import { SearchIcon } from './icon/SearchIcon';
@@ -219,8 +219,8 @@ export const Search = React.memo<{
219219
},
220220
[allComponents, dataset.hash, getLastViewed, makeFuse]
221221
);
222-
223-
const input = inputValue ? inputValue.trim() : '';
222+
const deferredQuery = useDeferredValue(inputValue);
223+
const input = deferredQuery ? deferredQuery.trim() : '';
224224
const results = input ? getResults(input) : [];
225225

226226
return (

0 commit comments

Comments
 (0)