mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
27 lines
670 B
JavaScript
27 lines
670 B
JavaScript
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) => {
|
|
if (!key) {
|
|
// delete query
|
|
return app.history.replace(window.location.pathname)
|
|
}
|
|
|
|
return app.history.replace(`${window.location.pathname}?${queryKey}=${key}`)
|
|
}
|
|
|
|
const changeActiveKey = (key) => {
|
|
setActiveKey(key)
|
|
replaceQueryTypeToCurrentTab(key)
|
|
}
|
|
|
|
return [
|
|
activeKey,
|
|
changeActiveKey,
|
|
]
|
|
} |