2024-06-11 17:13:45 +00:00

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