| Server IP : 109.122.246.182 / Your IP : 216.73.216.59 Web Server : Apache/2 System : Linux host3.abrin.cloud 6.1.0-52-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.180-1 (2026-08-03) x86_64 User : sinah533 ( 1085) PHP Version : 8.1.28 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/sinah533/public_html/wp-content/plugins/code-snippets/js/utils/ |
Upload File : |
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]
}