use-query-params
Advanced tools
Comparing version 1.2.2 to 1.2.3
export * from 'serialize-query-params'; | ||
export * from './types'; | ||
export { useQueryParam } from './useQueryParam'; | ||
@@ -3,0 +4,0 @@ export { useQueryParams } from './useQueryParams'; |
import { QueryParamConfig } from 'serialize-query-params'; | ||
import { UrlUpdateType } from './types'; | ||
declare type NewValueType<D> = D | ((latestValue: D) => D); | ||
@@ -17,3 +18,3 @@ /** | ||
*/ | ||
export declare const useQueryParam: <D, D2 = D>(name: string, paramConfig?: QueryParamConfig<D, D2>) => [D2, (newValue: NewValueType<D>, updateType?: "replace" | "push" | "replaceIn" | "pushIn" | undefined) => void]; | ||
export declare const useQueryParam: <D, D2 = D>(name: string, paramConfig?: QueryParamConfig<D, D2>) => [D2, (newValue: NewValueType<D>, updateType?: UrlUpdateType | undefined) => void]; | ||
export {}; |
@@ -17,3 +17,3 @@ import * as React from 'react'; | ||
*/ | ||
export declare function withQueryParams<QPCMap extends QueryParamConfigMap, P extends InjectedQueryProps<QPCMap>>(paramConfigMap: QPCMap, WrappedComponent: React.ComponentType<P>): React.FC<Pick<P, Exclude<keyof P, "query" | "setQuery">>>; | ||
export declare function withQueryParams<QPCMap extends QueryParamConfigMap, P extends InjectedQueryProps<QPCMap>>(paramConfigMap: QPCMap, WrappedComponent: React.ComponentType<P>): React.FC<Diff<P, InjectedQueryProps<QPCMap>>>; | ||
export default withQueryParams; | ||
@@ -28,2 +28,2 @@ /** | ||
*/ | ||
export declare function withQueryParamsMapped<QPCMap extends QueryParamConfigMap, MappedProps extends object, P extends MappedProps>(paramConfigMap: QPCMap, mapToProps: (query: DecodedValueMap<QPCMap>, setQuery: SetQuery<QPCMap>, props: Diff<P, MappedProps>) => MappedProps, WrappedComponent: React.ComponentType<P>): React.FC<Pick<P, Exclude<keyof P, keyof MappedProps>>>; | ||
export declare function withQueryParamsMapped<QPCMap extends QueryParamConfigMap, MappedProps extends object, P extends MappedProps>(paramConfigMap: QPCMap, mapToProps: (query: DecodedValueMap<QPCMap>, setQuery: SetQuery<QPCMap>, props: Diff<P, MappedProps>) => MappedProps, WrappedComponent: React.ComponentType<P>): React.FC<Diff<P, MappedProps>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getSSRSafeSearchString = exports.useUpdateRefIfShallowNew = void 0; | ||
var React = require("react"); | ||
@@ -4,0 +5,0 @@ var query_string_1 = require("query-string"); |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("serialize-query-params")); | ||
exports.QueryParamProvider = exports.QueryParams = exports.withQueryParamsMapped = exports.withQueryParams = exports.useQueryParams = exports.useQueryParam = void 0; | ||
__exportStar(require("serialize-query-params"), exports); | ||
__exportStar(require("./types"), exports); | ||
var useQueryParam_1 = require("./useQueryParam"); | ||
exports.useQueryParam = useQueryParam_1.useQueryParam; | ||
Object.defineProperty(exports, "useQueryParam", { enumerable: true, get: function () { return useQueryParam_1.useQueryParam; } }); | ||
var useQueryParams_1 = require("./useQueryParams"); | ||
exports.useQueryParams = useQueryParams_1.useQueryParams; | ||
Object.defineProperty(exports, "useQueryParams", { enumerable: true, get: function () { return useQueryParams_1.useQueryParams; } }); | ||
var withQueryParams_1 = require("./withQueryParams"); | ||
exports.withQueryParams = withQueryParams_1.withQueryParams; | ||
exports.withQueryParamsMapped = withQueryParams_1.withQueryParamsMapped; | ||
Object.defineProperty(exports, "withQueryParams", { enumerable: true, get: function () { return withQueryParams_1.withQueryParams; } }); | ||
Object.defineProperty(exports, "withQueryParamsMapped", { enumerable: true, get: function () { return withQueryParams_1.withQueryParamsMapped; } }); | ||
var QueryParams_1 = require("./QueryParams"); | ||
exports.QueryParams = QueryParams_1.QueryParams; | ||
Object.defineProperty(exports, "QueryParams", { enumerable: true, get: function () { return QueryParams_1.QueryParams; } }); | ||
var QueryParamProvider_1 = require("./QueryParamProvider"); | ||
exports.QueryParamProvider = QueryParamProvider_1.QueryParamProvider; | ||
Object.defineProperty(exports, "QueryParamProvider", { enumerable: true, get: function () { return QueryParamProvider_1.QueryParamProvider; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LocationProvider = exports.useLocationContext = exports.LocationContext = void 0; | ||
var React = require("react"); | ||
@@ -4,0 +5,0 @@ var updateUrlQuery_1 = require("./updateUrlQuery"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sharedMemoizedQueryParser = exports.makeMemoizedQueryParser = void 0; | ||
var query_string_1 = require("query-string"); | ||
exports.makeMemoizedQueryParser = function (initialSearchString) { | ||
var makeMemoizedQueryParser = function (initialSearchString) { | ||
var cachedSearchString = initialSearchString; | ||
@@ -15,2 +16,3 @@ var cachedParsedQuery = query_string_1.parse(cachedSearchString || ''); | ||
}; | ||
exports.makeMemoizedQueryParser = makeMemoizedQueryParser; | ||
exports.sharedMemoizedQueryParser = exports.makeMemoizedQueryParser(); |
@@ -14,2 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.QueryParamProvider = exports.getLocationProps = void 0; | ||
var React = require("react"); | ||
@@ -16,0 +17,0 @@ var LocationProvider_1 = require("./LocationProvider"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.QueryParams = void 0; | ||
var useQueryParams_1 = require("./useQueryParams"); | ||
exports.QueryParams = function (_a) { | ||
var QueryParams = function (_a) { | ||
var config = _a.config, children = _a.children; | ||
@@ -9,2 +10,3 @@ var _b = useQueryParams_1.default(config), query = _b[0], setQuery = _b[1]; | ||
}; | ||
exports.QueryParams = QueryParams; | ||
exports.default = exports.QueryParams; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateUrlQuery = exports.createLocationWithChanges = void 0; | ||
var serialize_query_params_1 = require("serialize-query-params"); | ||
@@ -4,0 +5,0 @@ /** |
import { QueryParamConfig } from 'serialize-query-params'; | ||
import { UrlUpdateType } from './types'; | ||
declare type NewValueType<D> = D | ((latestValue: D) => D); | ||
@@ -17,3 +18,3 @@ /** | ||
*/ | ||
export declare const useQueryParam: <D, D2 = D>(name: string, paramConfig?: QueryParamConfig<D, D2>) => [D2, (newValue: NewValueType<D>, updateType?: "replace" | "push" | "replaceIn" | "pushIn" | undefined) => void]; | ||
export declare const useQueryParam: <D, D2 = D>(name: string, paramConfig?: QueryParamConfig<D, D2>) => [D2, (newValue: NewValueType<D>, updateType?: UrlUpdateType | undefined) => void]; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useQueryParam = void 0; | ||
var React = require("react"); | ||
@@ -58,3 +59,3 @@ var serialize_query_params_1 = require("serialize-query-params"); | ||
*/ | ||
exports.useQueryParam = function (name, paramConfig) { | ||
var useQueryParam = function (name, paramConfig) { | ||
if (paramConfig === void 0) { paramConfig = serialize_query_params_1.StringParam; } | ||
@@ -101,1 +102,2 @@ var _a = LocationProvider_1.useLocationContext(), location = _a.location, getLocation = _a.getLocation, setLocation = _a.setLocation; | ||
}; | ||
exports.useQueryParam = useQueryParam; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useQueryParams = void 0; | ||
var React = require("react"); | ||
@@ -72,3 +73,3 @@ var serialize_query_params_1 = require("serialize-query-params"); | ||
*/ | ||
exports.useQueryParams = function (paramConfigMap) { | ||
var useQueryParams = function (paramConfigMap) { | ||
var _a = LocationProvider_1.useLocationContext(), location = _a.location, getLocation = _a.getLocation, setLocation = _a.setLocation; | ||
@@ -123,2 +124,3 @@ // read in the raw query | ||
}; | ||
exports.useQueryParams = useQueryParams; | ||
exports.default = exports.useQueryParams; |
@@ -17,3 +17,3 @@ import * as React from 'react'; | ||
*/ | ||
export declare function withQueryParams<QPCMap extends QueryParamConfigMap, P extends InjectedQueryProps<QPCMap>>(paramConfigMap: QPCMap, WrappedComponent: React.ComponentType<P>): React.FC<Pick<P, Exclude<keyof P, "query" | "setQuery">>>; | ||
export declare function withQueryParams<QPCMap extends QueryParamConfigMap, P extends InjectedQueryProps<QPCMap>>(paramConfigMap: QPCMap, WrappedComponent: React.ComponentType<P>): React.FC<Diff<P, InjectedQueryProps<QPCMap>>>; | ||
export default withQueryParams; | ||
@@ -28,2 +28,2 @@ /** | ||
*/ | ||
export declare function withQueryParamsMapped<QPCMap extends QueryParamConfigMap, MappedProps extends object, P extends MappedProps>(paramConfigMap: QPCMap, mapToProps: (query: DecodedValueMap<QPCMap>, setQuery: SetQuery<QPCMap>, props: Diff<P, MappedProps>) => MappedProps, WrappedComponent: React.ComponentType<P>): React.FC<Pick<P, Exclude<keyof P, keyof MappedProps>>>; | ||
export declare function withQueryParamsMapped<QPCMap extends QueryParamConfigMap, MappedProps extends object, P extends MappedProps>(paramConfigMap: QPCMap, mapToProps: (query: DecodedValueMap<QPCMap>, setQuery: SetQuery<QPCMap>, props: Diff<P, MappedProps>) => MappedProps, WrappedComponent: React.ComponentType<P>): React.FC<Diff<P, MappedProps>>; |
@@ -14,2 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withQueryParamsMapped = exports.withQueryParams = void 0; | ||
var React = require("react"); | ||
@@ -16,0 +17,0 @@ var useQueryParams_1 = require("./useQueryParams"); |
{ | ||
"name": "use-query-params", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "React Hook for managing state in URL query parameters with easy serialization.", | ||
@@ -44,38 +44,29 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.5", | ||
"@babel/preset-react": "^7.9.4", | ||
"@babel/preset-typescript": "^7.9.0", | ||
"@testing-library/jest-dom": "^4.1.0", | ||
"@testing-library/react": "^9.1.4", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"@types/history": "^4.7.5", | ||
"@types/jest": "^24.0.11", | ||
"@types/react": "^16.8.25", | ||
"@types/react-router": "^5.1.7", | ||
"@types/react-router-dom": "^5.1.5", | ||
"@typescript-eslint/eslint-plugin": "^2.28.0", | ||
"@typescript-eslint/parser": "^2.2.0", | ||
"babel-jest": "^25.3.0", | ||
"cross-env": "^7.0.2", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-react": "^7.14.3", | ||
"eslint-plugin-react-hooks": "^2.1.2", | ||
"@babel/preset-react": "^7.13.13", | ||
"@testing-library/jest-dom": "^5.12.0", | ||
"@testing-library/react": "^11.2.6", | ||
"@testing-library/react-hooks": "^5.1.2", | ||
"@types/history": "^4.7.8", | ||
"@types/react": "^17.0.4", | ||
"@types/react-router": "^5.1.13", | ||
"@types/react-router-dom": "^5.1.7", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^7.25.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-react": "^7.23.2", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"history": "^4.10.1", | ||
"husky": "^3.0.5", | ||
"jest": "^25.3.0", | ||
"lint-staged": "^9.2.5", | ||
"prettier": "^2.0.4", | ||
"query-string": "^6.12.1", | ||
"husky": "^6.0.0", | ||
"lint-staged": "^10.5.4", | ||
"prettier": "^2.2.1", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-router": "^5.1.2", | ||
"react-router-dom": "^5.1.2", | ||
"react-test-renderer": "^16.9.0", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^3.8.3" | ||
"react-router": "^5.2.0", | ||
"react-router-dom": "^5.2.0", | ||
"react-test-renderer": "^17.0.2" | ||
}, | ||
"peerDependencies": { | ||
"query-string": "^5.1.1 || ^6 || ^7", | ||
"query-string": ">=5.1.1", | ||
"react": ">=16.8.0", | ||
@@ -85,3 +76,3 @@ "react-dom": ">=16.8.0" | ||
"dependencies": { | ||
"serialize-query-params": "^1.3.3" | ||
"serialize-query-params": "^1.3.5" | ||
}, | ||
@@ -102,3 +93,4 @@ "husky": { | ||
] | ||
} | ||
}, | ||
"gitHead": "8b9a5a62e12eba3c9910039c33362090ccba54fe" | ||
} |
@@ -19,3 +19,3 @@ <div align="center"> | ||
<a href="#api">API</a> | | ||
<a href="https://peterbeshai.com/use-query-params/">Demo</a> | ||
<a href="https://pbeshai.github.io/use-query-params/">Demo</a> | ||
@@ -25,3 +25,3 @@ </div> | ||
When creating apps with easily shareable URLs, you often want to encode state as query parameters, but all query parameters must be encoded as strings. `useQueryParams` allows you to easily encode and decode data of any type as query parameters with smart memoization to prevent creating unnecessary duplicate objects. It uses [serialize-query-params](https://github.com/pbeshai/serialize-query-params). | ||
When creating apps with easily shareable URLs, you often want to encode state as query parameters, but all query parameters must be encoded as strings. `useQueryParams` allows you to easily encode and decode data of any type as query parameters with smart memoization to prevent creating unnecessary duplicate objects. It uses [serialize-query-params](../serialize-query-params/). | ||
@@ -39,3 +39,3 @@ | ||
Link your routing system (e.g., [React Router example](https://github.com/pbeshai/use-query-params/blob/master/examples/react-router/src/index.tsx), [Reach Router example](https://github.com/pbeshai/use-query-params/blob/master/examples/reach-router/src/index.tsx)): | ||
Link your routing system (e.g., [React Router example](./examples/react-router/src/index.tsx), [Reach Router example](./examples/reach-router/src/index.tsx)): | ||
@@ -233,6 +233,6 @@ ```js | ||
A few basic [examples](https://github.com/pbeshai/use-query-params/tree/master/examples) have been put together to demonstrate how `useQueryParams` works with different routing systems. | ||
A few basic [examples](./examples) have been put together to demonstrate how `useQueryParams` works with different routing systems. | ||
- [React Router Example](https://github.com/pbeshai/use-query-params/tree/master/examples/react-router) | ||
- [Reach Router Example](https://github.com/pbeshai/use-query-params/tree/master/examples/reach-router) | ||
- [React Router Example](./examples/react-router) | ||
- [Reach Router Example](./examples/reach-router) | ||
@@ -251,6 +251,6 @@ The React Router and Reach Router examples contain simple tests showing how to use the library with [React Testing Library](https://testing-library.com/docs/react-testing-library/intro). | ||
- [QueryParamProvider](#queryparamprovider) | ||
- [Type Definitions](https://github.com/pbeshai/use-query-params/blob/master/src/types.ts) and from [serialize-query-params](https://github.com/pbeshai/serialize-query-params/blob/master/src/types.ts). | ||
- [Serialization Utility Functions](https://github.com/pbeshai/serialize-query-params/blob/master/src/serialize.ts) | ||
- [Type Definitions](./src/types.ts) and from [serialize-query-params](../serialize-query-params/src/types.ts). | ||
- [Serialization Utility Functions](../serialize-query-params/src/serialize.ts) | ||
For convenience, use-query-params exports all of the [serialize-query-params](https://github.com/pbeshai/serialize-query-params) library. | ||
For convenience, use-query-params exports all of the [serialize-query-params](../serialize-query-params) library. | ||
@@ -267,3 +267,3 @@ #### UrlUpdateType | ||
#### Param Types | ||
See [all param definitions from serialize-query-params here](https://github.com/pbeshai/serialize-query-params/blob/master/src/params.ts). You can define your own parameter types by creating an object with an `encode` and a `decode` function. See the existing definitions for examples. | ||
See [all param definitions from serialize-query-params here](../serialize-query-params/src/params.ts). You can define your own parameter types by creating an object with an `encode` and a `decode` function. See the existing definitions for examples. | ||
@@ -306,3 +306,3 @@ Note that all null and empty values are typically treated as follows: | ||
You can define your own params if the ones shipped with this package don't work for you. There are included [serialization utility functions](https://github.com/pbeshai/serialize-query-params/blob/master/src/serialize.ts) to make this easier, but you can use whatever you like. | ||
You can define your own params if the ones shipped with this package don't work for you. There are included [serialization utility functions](../serialize-query-params/src/serialize.ts) to make this easier, but you can use whatever you like. | ||
@@ -451,3 +451,3 @@ ```js | ||
Note there is also a variant called `withQueryParamsMapped` that allows you to do a react-redux style mapStateToProps equivalent. See [the code](https://github.com/pbeshai/use-query-params/blob/master/src/withQueryParams.tsx#L51) or [this example](https://github.com/pbeshai/use-query-params/blob/master/examples/react-router/src/ReadmeExample3Mapped.tsx) for details. | ||
Note there is also a variant called `withQueryParamsMapped` that allows you to do a react-redux style mapStateToProps equivalent. See [the code](./src/withQueryParams.tsx#L51) or [this example](./examples/react-router/src/ReadmeExample3Mapped.tsx) for details. | ||
@@ -541,4 +541,4 @@ <br/> | ||
- [React Router Example](https://github.com/pbeshai/use-query-params/tree/master/examples/react-router) | ||
- [Reach Router Example](https://github.com/pbeshai/use-query-params/tree/master/examples/reach-router) | ||
- [React Router Example](./examples/react-router) | ||
- [Reach Router Example](./examples/reach-router) | ||
@@ -545,0 +545,0 @@ |
96995
24
1664
+ Addeddecode-uri-component@0.4.1(transitive)
+ Addedfilter-obj@5.1.0(transitive)
+ Addedquery-string@9.0.0(transitive)
+ Addedsplit-on-first@3.0.0(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removedfilter-obj@1.1.0(transitive)
- Removedquery-string@7.1.3(transitive)
- Removedsplit-on-first@1.1.0(transitive)
- Removedstrict-uri-encode@2.0.0(transitive)