我在自己的React应用程序中使用Algolia进行自动填充。但是我在开发过程中遇到了一些问题:
- 如果我不输入任何内容,则自动填充功能已经具有标准点击率,该如何将其关闭?
- 由于现在1个字符要花1个操作(可能会有类型延迟),因此如何减少操作?
我正在使用CefSharp
和algoliasearch/lite
软件包。
React InstantSearch不能立即提供此选项。您必须实现searchClient
版本,才能在空状态下中止请求。您可以在documentation中找到指南。
您不能直接使用此行为。您可以自己实现它。这种模式称为反跳。 documentation中还有一个专门的章节。
currentRefinement
不为空的情况下呈现匹配:
import { connectAutoComplete } from 'react-instantsearch-dom';
const Autocomplete = ({ hits,currentRefinement,refine }) => (
<ul>
<li>
<input
type="search"
value={currentRefinement}
onChange={event => refine(event.currentTarget.value)}
/>
</li>
//Render only if currentRefinement not empty
{currentRefinement && (
hits.map(hit => (
<li key={hit.objectID}>{hit.name}</li>
))
)}
</ul>
);
const CustomAutocomplete = connectAutoComplete(Autocomplete);
SearchBox
示例代码documentation