mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
✨ Added new useUrlQueryActiveKey
hook
This commit is contained in:
parent
8f26f1350e
commit
fe11eef2da
22
packages/app/src/hooks/useUrlQueryActiveKey/index.js
Normal file
22
packages/app/src/hooks/useUrlQueryActiveKey/index.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import React from "react"
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
defaultKey = "0",
|
||||||
|
queryKey = "key",
|
||||||
|
}) => {
|
||||||
|
const [activeKey, setActiveKey] = React.useState(new URLSearchParams(window.location.search).get(queryKey) ?? defaultKey)
|
||||||
|
|
||||||
|
const replaceQueryTypeToCurrentTab = (key) => {
|
||||||
|
app.history.replace(`${window.location.pathname}?${queryKey}=${key}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const changeActiveKey = (key) => {
|
||||||
|
setActiveKey(key)
|
||||||
|
replaceQueryTypeToCurrentTab(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
activeKey,
|
||||||
|
changeActiveKey,
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user