Added new useUrlQueryActiveKey hook

This commit is contained in:
SrGooglo 2023-04-27 21:59:18 +00:00
parent 8f26f1350e
commit fe11eef2da

View 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,
]
}