mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
added hooks
This commit is contained in:
parent
02abdb3c5e
commit
69b3d5ef8d
2
packages/app/src/hooks/index.js
Executable file
2
packages/app/src/hooks/index.js
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
export { default as useHacks } from "./useHacks"
|
||||||
|
export { default as useCenteredContainer } from "./useCenteredContainer"
|
11
packages/app/src/hooks/useCenteredContainer/index.js
Executable file
11
packages/app/src/hooks/useCenteredContainer/index.js
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
import React from "react"
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
React.useEffect(() => {
|
||||||
|
app.layout.toogleCenteredContent(true)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
app.layout.toogleCenteredContent(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
}
|
29
packages/app/src/hooks/useHacks/index.js
Executable file
29
packages/app/src/hooks/useHacks/index.js
Executable 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]
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user