npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-instantsearch-nextjs

v0.3.17

Published

React InstantSearch SSR utilities for Next.js

Downloads

66,404

Readme

react-instantsearch-nextjs

This package provides server-side rendering for React InstantSearch that is compatible with Next.js 13 App Router.

[!WARNING] This package is experimental.

Installation

yarn add react-instantsearch-nextjs
# or with npm
npm install react-instantsearch-nextjs

Usage

[!NOTE] You can check this documentation on Algolia's Documentation website.

Your search component must be in its own file, and it shouldn't be named page.js or page.tsx.

To render the component in the browser and allow users to interact with it, include the "use client" directive at the top of your code.

+'use client';
import algoliasearch from 'algoliasearch/lite';
import {
  InstantSearch,
  SearchBox,
} from 'react-instantsearch';

const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');

export function Search() {
  return (
    <InstantSearch indexName="YourIndexName" searchClient={searchClient}>
      <SearchBox />
      {/* other widgets */}
    </InstantSearch>
  );
}

Import the <InstantSearchNext> component from the react-instantsearch-nextjs package, and replace the <InstantSearch> component with it, without changing the props.

'use client';
import algoliasearch from 'algoliasearch/lite';
import {
- InstantSearch,
  SearchBox,
} from 'react-instantsearch';
+import { InstantSearchNext } from 'react-instantsearch-nextjs';

const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');

export function Search() {
  return (
-   <InstantSearch indexName="YourIndexName" searchClient={searchClient}>
+   <InstantSearchNext indexName="YourIndexName" searchClient={searchClient}>
      <SearchBox />
      {/* other widgets */}

-   </InstantSearch>
+   </InstantSearchNext>
  );
}

To serve your search page at /search, create an app/search directory. Inside it, create a page.js file (or page.tsx if you're using TypeScript).

Make sure to configure your route segment to be dynamic so that Next.js generates a new page for each request.

// app/search/page.js or app/search/page.tsx
import { Search } from './Search'; // change this with the path to your <Search> component

export const dynamic = 'force-dynamic';

export default function Page() {
  return <Search />;
}

You can now visit /search to see your server-side rendered search page.

API

<InstantSearchNext>

The <InstantSearchNext> component is a drop-in replacement for the <InstantSearch> component. It accepts the same props, and it renders the same UI.

You can check the InstantSearch API reference for more information.

routing prop

As with the <InstantSearch> component, you can pass a routing prop to the <InstantSearchNext> component to customize the routing behavior. The difference here is that routing.router takes the same options as the historyRouter.

Troubleshooting

If you're experiencing issues, please refer to the Need help? section of the docs, or open a new issue.

Contributing

We welcome all contributors, from casual to regular 💙

To start contributing to code, you need to:

  1. Fork the project
  2. Clone the repository
  3. Install the dependencies: yarn

Please read our contribution process to learn more.

License

React InstantSearch is MIT licensed.