Socket
Socket
Sign inDemoInstall

use-query-params

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-query-params - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

LICENSE

21

esm/useQueryParam.js
import * as React from 'react';
import { parse as parseQueryString, stringify, StringParam, } from 'serialize-query-params';
import { parse as parseQueryString, parseUrl as parseQueryURL, stringify, StringParam, } from 'serialize-query-params';
import { QueryParamContext } from './QueryParamProvider';

@@ -22,7 +22,18 @@ import { updateUrlQuery } from './updateUrlQuery';

var _a = React.useContext(QueryParamContext), history = _a.history, location = _a.location;
// read in the raw query
if (!rawQuery) {
rawQuery = React.useMemo(function () { return parseQueryString(location.search) || {}; }, [
location.search,
]);
rawQuery = React.useMemo(function () {
var pathname = {};
// handle checking SSR (#13)
if (typeof location === 'object') {
// in browser
if (typeof window !== 'undefined') {
pathname = parseQueryString(location.search);
}
else {
// not in browser
pathname = parseQueryURL(location.pathname).query;
}
}
return pathname || {};
}, [location.search, location.pathname]);
}

@@ -29,0 +40,0 @@ // read in the encoded string value

@@ -24,7 +24,18 @@ "use strict";

var _a = React.useContext(QueryParamProvider_1.QueryParamContext), history = _a.history, location = _a.location;
// read in the raw query
if (!rawQuery) {
rawQuery = React.useMemo(function () { return serialize_query_params_1.parse(location.search) || {}; }, [
location.search,
]);
rawQuery = React.useMemo(function () {
var pathname = {};
// handle checking SSR (#13)
if (typeof location === 'object') {
// in browser
if (typeof window !== 'undefined') {
pathname = serialize_query_params_1.parse(location.search);
}
else {
// not in browser
pathname = serialize_query_params_1.parseUrl(location.pathname).query;
}
}
return pathname || {};
}, [location.search, location.pathname]);
}

@@ -31,0 +42,0 @@ // read in the encoded string value

{
"name": "use-query-params",
"version": "0.3.3",
"version": "0.3.4",
"description": "React Hook for managing state in URL query parameters with easy serialization.",

@@ -21,2 +21,4 @@ "main": "lib/index.js",

"prepublishOnly": "npm run test && npm run build",
"lint": "eslint --ext js,ts,tsx src",
"prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
"test": "jest",

@@ -49,4 +51,11 @@ "test-watch": "jest --watch",

"@types/react": "^16.8.7",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"babel-jest": "^24.5.0",
"eslint": "^6.3.0",
"eslint-plugin-react": "^7.14.3",
"husky": "^3.0.5",
"jest": "^24.5.0",
"lint-staged": "^9.2.5",
"prettier": "^1.18.2",
"react": "^16.8.4",

@@ -60,8 +69,23 @@ "react-dom": "^16.8.4",

"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"dependencies": {
"serialize-query-params": "^0.1.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md}": [
"prettier --write",
"git add"
],
"*.{js,ts,tsx}": [
"eslint --fix",
"git add"
]
}
}
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