algolia / react-instantsearch

⚡️ Lightning-fast search for React and React Native applications, by Algolia.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/react/
MIT License
1.97k stars 386 forks source link

findResultsState with Nextjs useRouter makes router null when pre-rendering #3620

Closed foldess closed 1 year ago

foldess commented 1 year ago

🐛 Bug description

When using findResultsState inside nextjs function getStaticProps the nextjs router object declared using const router = useRouter() is null instead of Server Router

🔍 Bug reproduction

Steps to reproduce the behavior:

  1. Clone repo test Repository
  2. run build
  3. Look at logs

💭 Expected behavior

Router should not be undefined but server router instance

🖥 Screenshots

image

Environment

dhayab commented 1 year ago

Hi, that's because findResultsState() renders the component with no knowledge of Next.js Router context, so you need to provide it explicitly. You can check https://github.com/algolia/react-instantsearch/issues/3524#issuecomment-1160078935 for more info.