Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
react-instantsearch-router-nextjs
Advanced tools
This package is a router for React InstantSearch that is compatible with Next.js routing.
:warning: This function cannot be used in conjunction with
getStaticProps()
. UsegetServerSideProps()
or client-side rendering instead.
yarn add react-instantsearch-router-nextjs
# or with npm
npm install react-instantsearch-router-nextjs
You need to pass the Next.js router singleton that you can import from next/router
.
If you are doing SSR with the getServerState
and InstantSearchSSRProvider
from react-instantsearch/server
, you need to pass the url
prop to createInstantSearchRouterNext
's serverUrl
option :
import singletonRouter from 'next/router';
import { createInstantSearchRouterNext } from 'react-instantsearch-router-nextjs';
export default function Page({ serverState, url }) {
return (
<InstantSearchSSRProvider {...serverState}>
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
routing={{
router: createInstantSearchRouterNext({
singletonRouter,
serverUrl: url,
}),
}}
>
{/* ... */}
</InstantSearch>
</InstantSearchSSRProvider>
);
}
If you are not doing SSR but only CSR, you can omit the serverUrl
option:
import singletonRouter from 'next/router';
import { createInstantSearchRouterNext } from 'react-instantsearch-router-nextjs';
export default function Page() {
return (
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
routing={{ router: createInstantSearchRouterNext({ singletonRouter }) }}
>
{/* ... */}
</InstantSearch>
);
}
Lastly, if you had custom routing logic in your app, you can pass it to the createInstantSearchRouterNext
's routerOptions
option:
import singletonRouter from 'next/router';
import { createInstantSearchRouterNext } from 'react-instantsearch-router-nextjs';
export default function Page({ serverState, url }) {
return (
{/* ... */}
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
routing={{
router: createInstantSearchRouterNext({
singletonRouter,
serverUrl: url,
routerOptions: {
createURL: /* ... */,
parseURL: /* ... */,
},
}),
// if you are using a custom `stateMapping` you can still pass it :
stateMapping: /* ... */,
}}
>
{/* ... */}
</InstantSearch>
{/* ... */}
);
}
The options are :
singletonRouter: SingletonRouter
: the required Next.js router singleton.serverUrl?: string
: the URL of the page on the server. Required if you are doing SSR with getServerState
and InstantSearchSSRProvider
.routerOptions?: RouterOptions
: the options passed to the history
router. See the documentation for more details.For troubleshooting purposes, some other options are available :
beforeStart?: (onUpdate: () => void) => void
: a function called before the router starts. You can use it to inform InstantSearch to update on router events by calling onUpdate
.beforeDispose?: () => void
: a function called before the router disposes. You can use it to clean up handlers you added in beforeStart
.beforePopState?: (options: { state: NextHistoryState, ownBeforePopState: BeforePopStateCallback, libraryBeforePopState: BeforePopStateCallback }) => boolean
: a function used by the Next.js router to know whether it should trigger SSR when using back/forward buttons. You can use it to override the default one by writing your own logic. The ownBeforePopState
is the pre-existing handler that you may have set yourself, and the libraryBeforePopState
is the default one from the library.If you're experiencing issues, please refer to the Need help? section of the docs, or open a new issue.
We welcome all contributors, from casual to regular 💙
To start contributing to code, you need to:
yarn
Please read our contribution process to learn more.
React InstantSearch is MIT licensed.
FAQs
React InstantSearch Router for Next.js
The npm package react-instantsearch-router-nextjs receives a total of 15,665 weekly downloads. As such, react-instantsearch-router-nextjs popularity was classified as popular.
We found that react-instantsearch-router-nextjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.