algolia / instantsearch

⚑️ Libraries for building performant and instant search experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.

Home Page:https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remix useFetcher() cannot be used inside InstantSearch

lildesert opened this issue Β· comments

πŸ› Current behavior

Hi,

One of the numerous frustrations I got from trying to use algolia with Remix is that I cannot use useFetcher() in any component that is a child of <InstantSearch>.
The InstantSearch component affects the react-router behavior (which Remix uses under the hood).
On new versions of Remix, the thrown error is the following useFetcher must be used inside a RouteContext. So I guess InstantSearchContext doesn't pair well with Remix RouteContext.

Small edit: it seems related to SSR since an easy workaround is to render the component only client-side with ClientOnly for example.

Thanks for any help on this!

πŸ” Steps to reproduce

Just use Remix useFetcher in any component inside . See sandbox for reproduction.

Live reproduction

https://codesandbox.io/p/sandbox/remix-algolia-usefetcher-h3x9rh

πŸ’­ Expected behavior

useFetcher() works out of the box and allows me to fetch or post data.

Package version

react-instantsearch 7.2.0, remix 2.2.0, algoliasearch 4.20.0

Operating system

No response

Browser

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hi @lildesert

The problem is the component is not being rendered in the Remix context it needs.

There are 2 ways to circumvent this :