Socket
Socket
Sign inDemoInstall

zustand-querystring

Package Overview
Dependencies
1
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    zustand-querystring

A Zustand middleware that syncs the store with the querystring.


Version published
Weekly downloads
605
decreased by-11.29%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

zustand-querystring

A Zustand middleware that syncs the store with the querystring.

Try on StackBlitz (You need to click "Open in New Tab")

Examples:

Quickstart:

import create from 'zustand';
import { querystring } from 'zustand-querystring';

interface Store {
  count: number;
  ticks: number;
  someNestedState: {
    nestedCount: number;
    hello: string;
  };
}

export const useStore = create<Store>()(
  querystring(
    (set, get) => ({
      count: 0,
      ticks: 0,
      someNestedState: {
        nestedCount: 0,
        hello: 'Hello',
      },
    }),
    {
      // select controls what part of the state is synced with the query string
      // pathname is the current route (e.g. /about or /)
      select(pathname) {
        return {
          count: true,
          // ticks: false, <- false by default

          someNestedState: {
            nestedCount: true,
            hello: '/about' === pathname,
          },

          // OR select the whole nested state
          // someNestedState: true
        };
      },
    },
  ),
);

querystring options:

  • select - the select option controls what part of the state is synced with the query string
  • key: string - the key option controls how the state is stored in the querystring (default: $)
  • url - the url option is used to provide the request url on the server side render

Keywords

FAQs

Last updated on 12 Jan 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc