| Linux webm007.cluster106.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 Path : /home/eglisebaa/www/wp-content/plugins/code-snippets/js/utils/ |
| Current File : /home/eglisebaa/www/wp-content/plugins/code-snippets/js/utils/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]
}