From 2244cd65bda8f8f01f7e91afd8bad80961ea565d Mon Sep 17 00:00:00 2001 From: Meghea Iulian Date: Wed, 18 May 2022 11:35:52 +0300 Subject: [PATCH] feat(hash-param)!: add setter support --- lib/use-hash-param.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/use-hash-param.js b/lib/use-hash-param.js index b9090f6..30f04f7 100644 --- a/lib/use-hash-param.js +++ b/lib/use-hash-param.js @@ -41,5 +41,16 @@ export const link = (hashParam, value) => { }; }, [parameterized]); - return param; + const set = useMemo( + () => + hashParam + ? (v) => { + setParam(v); + history.pushState({}, '', link(v)); + } + : setParam, + [hashParam] + ); + + return [param, set]; };