added hooks

This commit is contained in:
SrGooglo 2023-03-14 19:49:29 +00:00
parent 02abdb3c5e
commit 69b3d5ef8d
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,2 @@
export { default as useHacks } from "./useHacks"
export { default as useCenteredContainer } from "./useCenteredContainer"

View File

@ -0,0 +1,11 @@
import React from "react"
export default () => {
React.useEffect(() => {
app.layout.toogleCenteredContent(true)
return () => {
app.layout.toogleCenteredContent(false)
}
}, [])
}

View File

@ -0,0 +1,29 @@
import React from "react"
export default (hacks, options = {}) => {
if (typeof options.namespace === "undefined") {
// if no namespace is provided, use the name of the calling function
const stack = new Error().stack
const caller = stack.split("\n")[2].trim()
const match = caller.match(/at ([^(]+) \(/)
if (match) {
options.namespace = match[1]
}
}
if (!options.namespace) {
throw new Error("No namespace provided for hacks")
}
React.useEffect(() => {
if (!window._hacks) {
window._hacks = {}
}
window._hacks[options.namespace] = hacks
return () => {
delete window._hacks[options.namespace]
}
}, [])
}