Skip to content

Commit f42543a

Browse files
docs: fix customSearchFunction example #1874
* React Hook "useChatContext" is called in function "customSearchFunction" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use" * setResultsOpen does not exist Co-authored-by: Guido van de Riet <[email protected]>
1 parent 7dced57 commit f42543a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

docusaurus/docs/React/guides/customization/channel-search.mdx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,26 +317,37 @@ To override the search method, completely use the `searchFunction` prop. This pr
317317
and for only channels that the current logged in user is a member of. See the example below for this.
318318
319319
```jsx
320-
const customSearchFunction = async (props: ChannelSearchFunctionParams, event: { target: { value: SetStateAction<string>; }; }) => {
321-
const { setResults, setResultsOpen, setSearching, setQuery } = props;
322-
const { client } = useChatContext();
320+
const customSearchFunction = async (
321+
props: ChannelSearchFunctionParams,
322+
event: { target: { value: SetStateAction<string> } },
323+
client: StreamChat
324+
) => {
325+
const { setResults, setSearching, setQuery } = props;
326+
const value = event.target.value;
323327

324328
const filters = {
325-
name: { $autocomplete: event.target.value },
329+
name: { $autocomplete: value },
326330
members: { $in: client.userID }
327331
}
328332

329333
setSearching(true);
330-
setQuery(event.target.value);
331-
const channels = await chatClient.queryChannels(filters);
334+
setQuery(value);
335+
const channels = await client.queryChannels(filters);
332336
setResults(channels);
333-
setResultsOpen(true);
334337
setSearching(false);
335338
};
339+
```
340+
341+
```jsx
342+
const { client } = useChatContext();
336343

337344
<ChannelList
345+
additionalChannelSearchProps={{
346+
searchFunction: (params, event) => {
347+
return customSearchFunction(params, event, client);
348+
},
349+
}}
338350
showChannelSearch
339-
additionalChannelSearchProps={{searchFunction: customSearchFunction}}
340351
/>
341352
```
342353

0 commit comments

Comments
 (0)