use-navigation-api 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -1
- package/src/index.ts +3 -2
- package/src/location/useLocationWithParam.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-navigation-api",
|
|
3
3
|
"private": false,
|
|
4
|
+
"description": "Simple Navigation API integration for React",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/lvlvllvlvllvlvl/use-navigation-api.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/lvlvllvlvllvlvl/use-navigation-api/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/lvlvllvlvllvlvl/use-navigation-api#readme",
|
|
4
14
|
"main": "./dist/use-navigation-api.umd.js",
|
|
5
15
|
"module": "./dist/use-navigation-api.es.js",
|
|
6
16
|
"types": "./dist/index.d.ts",
|
|
@@ -11,7 +21,7 @@
|
|
|
11
21
|
"require": "./dist/use-navigation-api.umd.js"
|
|
12
22
|
}
|
|
13
23
|
},
|
|
14
|
-
"version": "0.0
|
|
24
|
+
"version": "0.1.0",
|
|
15
25
|
"type": "module",
|
|
16
26
|
"scripts": {
|
|
17
27
|
"build": "tsc -b && vite build",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./navigationProvider";
|
|
2
|
-
export * from "./location/useLocation.ts";
|
|
3
2
|
export * from "./useNavigate";
|
|
4
|
-
export * from "./location/
|
|
3
|
+
export * from "./location/useLocation";
|
|
4
|
+
export * from "./location/useQueryParam";
|
|
5
|
+
export * from "./location/useLocationWithParam";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLocation } from "src/location/useLocation.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* returns The current location with the specified parameter set to the provided value or removed if the value === null.
|
|
5
|
+
* @param param name of the query parameter to set
|
|
6
|
+
* @param value value to set the parameter to, or `null` to remove any existing value of that parameter
|
|
7
|
+
*/
|
|
8
|
+
export function useLocationWithParam(param: string, value: string | null) {
|
|
9
|
+
return useLocation((url) =>
|
|
10
|
+
value === null
|
|
11
|
+
? url.searchParams.delete(param)
|
|
12
|
+
: url.searchParams.set(param, value),
|
|
13
|
+
);
|
|
14
|
+
}
|