React debounce search 在初始化之前无法访问 'updateSearchQuery'

React debounce search Cannot access 'updateSearchQuery' before initialization

我正在尝试对我的 React 应用实施去抖动搜索。这是我当前处理搜索的代码:

const debouncedSearch = debounce(updateSearchQuery, 500);

const handleSearchInputChange = (searchText) => {
    debouncedSearch(searchText);
}

const updateSearchQuery = (searchText) => {
    setSearchQuery(searchText);
}

handleSearchInputChange 是这样调用的:

onSearchChange: (searchText) => {handleSearchInputChange(searchText)

这不起作用,因为我收到此错误:

ReferenceError: Cannot access 'updateSearchQuery' before initialization

关于可能导致此问题的原因有什么想法吗?

updateSearchQuery 的声明移到引用的上方:

const updateSearchQuery = (searchText) => {
    setSearchQuery(searchText);
}

const debouncedSearch = debounce(updateSearchQuery, 500);

const handleSearchInputChange = (searchText) => {
    debouncedSearch(searchText);
}