I'm trying react query and found useInfiniteQuery. then I start creating my infinite list of posts, but now I'd like to put an input to search for a specific post.
I have two endpoints: one for fetch all posts and the other to fetch by search.
how can I make that?
const [search, setSearch] = useState('');const { data, hasNextPage, fetchNextPage } = useInfiniteQuery( ['posts', search], ({ pageParam = 1 }) => !search ? getPosts(companiesPerPage, pageParam) : getPostsBySearch(search), { getNextPageParam: (lastPage, allPages) => { const maxPages = Math.ceil( lastPage.data.result.totalRecords / POSTS_PER_PAGE, ); const nextPage = allPages.length + 1; return nextPage <= maxPages ? nextPage : undefined; }, }, );return (<input type="text" value={search} onChange={e => setSearch(e.target.value) /><ul>{posts?.pages.map(page => page.data.result.data.map((post, post) => (<li key={post.id}>{post.title}</li> )), )}</ul>)