mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-28 14:04:43 -04:00
fix(explore): URL parameters override default value
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
485ac5a7a6
commit
0df149aba3
1 changed files with 5 additions and 2 deletions
|
@ -62,13 +62,16 @@ export const useUrlParamState = <T extends string | null = string>(
|
||||||
if (!searchParamsReact) {
|
if (!searchParamsReact) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const newValue = searchParamsReact.get(paramName) as T
|
let newValue = searchParamsReact.get(paramName) as T
|
||||||
|
if (newValue === null) {
|
||||||
|
newValue = typeof defaultValue === 'function' ? defaultValue() : defaultValue
|
||||||
|
}
|
||||||
if (newValue === lastSetValue.current) {
|
if (newValue === lastSetValue.current) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastSetValue.current = newValue
|
lastSetValue.current = newValue
|
||||||
setValue(newValue)
|
setValue(newValue)
|
||||||
}, [paramName, searchParamsReact])
|
}, [paramName, searchParamsReact, defaultValue])
|
||||||
|
|
||||||
return [value, onUpdate]
|
return [value, onUpdate]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue