Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-router-query

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-router-query

**Drop-in alternative of `useRouter().query` that tries it's best to get the query params on the first mount.**

  • 0.1.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

next-router-query

Drop-in alternative of useRouter().query that tries it's best to get the query params on the first mount.

Have you ever gotten annoyed by the fact that useRouter().query is an empty object on the first mount? Great, then this is a library for you.

Illustrating the difference

Given a page called post/[id].jsx that is called with /post/myId?key=value:

You will see something like this when first mounting the page:

useRouter().query // result: {} // 😢 

With next-router-query you'll see the difference

--------- Render #1  --------
useRouter().query result: {} // 😢 
useRouterQuery() result: {id: 'myId', key: 'value'} // 😻

Once the first render is done and useRouter().query returns data, we'll simply return that instead.

Caveats

  • Relies on URLSearchParams - you might need some polyfill
  • Only works in the browser - server will not show the right result

Install

yarn add next-router-query
# or 
npm i next-router-query

Usage

import { useRouterQuery } from 'next-router-query';

export function MyPage() {
  const routerQuery = useRouterQuery()

  // ...
}

FAQs

Package last updated on 21 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc