npm.io
0.2.2 • Published 6 years ago

query-params-data

Licence
MIT
Version
0.2.2
Deps
7
Size
17 kB
Vulns
0
Weekly
0
Stars
1

query-params-data

Actions Status

Easily control data in query params.

  • set data at a specific query param
  • subscribe to changes of data at different query param keys.

Usage

import UrlStore from 'query-params-data';

// control the `user_id` query param
const userIdUrlStore = new UrlStore('user_id');

// set data to the `user_id` query param
userIdUrlStore.setState('1');

// subscribe to changes of the `user_id` query param or get the existing state at startup
const onChange = state => console.log(`The current user id is ${state}`);
userIdUrlStore.subscribeToStateChanges(onChange);