mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
39 lines
767 B
JavaScript
39 lines
767 B
JavaScript
import React from "react"
|
|
|
|
const useClickNavById = (navigators = {}, itemFlagId = "div") => {
|
|
const ref = React.useRef(null)
|
|
|
|
async function onClick(e) {
|
|
const element = e.target.closest(itemFlagId ?? "div")
|
|
|
|
if (!element) {
|
|
console.error("Element not found")
|
|
return false
|
|
}
|
|
|
|
const id = element?.id
|
|
|
|
if (!id) {
|
|
console.error("Element id not found")
|
|
return false
|
|
}
|
|
|
|
const location = navigators[id]
|
|
|
|
if (!location) {
|
|
console.error("Location not found")
|
|
return false
|
|
}
|
|
|
|
app.location.push(location)
|
|
}
|
|
|
|
return [
|
|
ref,
|
|
{
|
|
onClick
|
|
}
|
|
]
|
|
}
|
|
|
|
export default useClickNavById |