You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

gatsby-query-params

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-query-params

Get query params of the current URL in Gatsby

1.3.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

gatsby-query-params

Get query params of the current URL in Gatsby

NPM JavaScript Style Guide

Install

npm add gatsby-query-params

Function Signature

  • getSearchParams - Return query parameters as an object.
import { getSearchParams } from "gatsby-query-params";

const searchParams = getSearchParams();
  • useQueryParam - Return query parameter for a specific key. If it doesn't exist, returns a set default value ( default null ).
import { useQueryParam } from "gatsby-query-params";

const value = useQueryParam(key, defaultValue);

Usage

import React, {useState, useEffect} from 'react'
import { useQueryParam, getSearchParams } from "gatsby-query-params";

function App() {
  
  const name = useQueryParam("name", "Akash"); // key, defaultValue
  console.log(name); // log query param
  console.log(getSearchParams()); // Log all parameters

  return (
    <div>
      Hello
    </div>
  )
}

export default App

Example

  • Run npm start on the root folder.
  • cd example
  • npm start

Where does this library run?

Both Client-Side Rendering (CSR) & Server-Side Rendering (SSR) are supported.

License

LGPLV3 © akash-joshi

Keywords

gatsby

FAQs

Package last updated on 04 Nov 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