You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many instances where your list of data may need to be filtered, such as during user lookup or query searches.
180
+
For server side filtering, this can be implemented by using the `filterText` option passed to the `load` function.
181
+
The `setFilterText` method updates the current `filterText` value and triggers the `load` function. This allows
182
+
you to reload the results with the new filter text.
183
+
184
+
### Server side filtering
185
+
186
+
The example below shows how server side filtering could be implemented by using `filterText` in the `load` function and passing a parameter to the API.
187
+
The input value of the ComboBox is controlled by providing `list.filterText` as the ComboBox's `inputValue` prop, and `list.setFilterText` as the `onInputChange` prop.
188
+
The `loadingState` prop is also used to show the appropriate loading indicator depending on the state of the list.
189
+
190
+
```tsx
191
+
let list =useAsyncList({
192
+
async load({signal, filterText}) {
193
+
let res =awaitfetch(`https://swapi.dev/api/people/?search=${filterText}`, {signal});
194
+
let json =awaitres.json();
195
+
196
+
return {
197
+
items: json.results
198
+
};
199
+
}
200
+
});
201
+
202
+
<ComboBox
203
+
label="Star Wars Character Lookup"
204
+
items={list.items}
205
+
inputValue={list.filterText}
206
+
onInputChange={list.setFilterText}
207
+
loadingState={list.loadingState}>
208
+
{item=> <Itemkey={item.name}>{item.name}</Item>}
209
+
</ComboBox>
210
+
```
211
+
177
212
## Pre-selecting items
178
213
179
214
`useAsyncList` manages selection state for the list in addition to its data. If you need to programmatically select items
0 commit comments