golden hour
/home/godaofbq/besthyperbaric.com/wp-content/plugins/code-snippets/js/utils
⬆️ Go Up
Upload
File/Folder
Size
Actions
.htaccess
420 B
Del
OK
Linter.ts
4.44 KB
Del
OK
errors.ts
80 B
Del
OK
files.ts
1.44 KB
Del
OK
hooks.ts
498 B
Del
OK
restAPI.ts
473 B
Del
OK
screen.ts
249 B
Del
OK
snippets
-
Del
OK
text.ts
787 B
Del
OK
Edit: hooks.ts
import { createContext, useContext } from 'react' import type { Context } from 'react' export const createContextHook = <T>(name: string): [ Context<T | undefined>, () => T ] => { const contextValue = createContext<T | undefined>(undefined) const useContextHook = (): T => { const value = useContext(contextValue) if (value === undefined) { throw Error(`use${name} can only be used within a ${name} context provider.`) } return value } return [contextValue, useContextHook] }
Save