/
ashipov
/
react
Обзор
Документация
Войти
/
ashipov
/
react
Код
Запросы
0
Задачи 2.0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
packages/react-devtools-shared/src/devtools/views/Components/ComponentSearchInput.js
52 строки
2 KB
Ruslan Lesiutin
[DevTools] fix: keep search query in a local sync state (#34423)
10 сен 2025, 20:38
Не верифицирован
10 сен 2025, 20:38
e2ba45b
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import * as React from 'react'; import {useState, useContext, useCallback} from 'react'; import SearchInput from 'react-devtools-shared/src/devtools/views/SearchInput'; import { TreeDispatcherContext, TreeStateContext, } from 'react-devtools-shared/src/devtools/views/Components/TreeContext'; export default function ComponentSearchInput(): React.Node { const [localSearchQuery, setLocalSearchQuery] = useState(''); const {searchIndex, searchResults} = useContext(TreeStateContext); const transitionDispatch = useContext(TreeDispatcherContext); const search = useCallback( (text: string) => { setLocalSearchQuery(text); transitionDispatch({type: 'SET_SEARCH_TEXT', payload: text}); }, [setLocalSearchQuery, transitionDispatch], ); const goToNextResult = useCallback( () => transitionDispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'}), [transitionDispatch], ); const goToPreviousResult = useCallback( () => transitionDispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'}), [transitionDispatch], ); return ( <SearchInput goToNextResult={goToNextResult} goToPreviousResult={goToPreviousResult} placeholder="Search (text or /regex/)" search={search} searchIndex={searchIndex} searchResultsCount={searchResults.length} searchText={localSearchQuery} testName="ComponentSearchInput" /> ); }