use-query-params
Advanced tools
Comparing version 0.3.3 to 0.3.4
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" | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69107
31
1444
21