芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/optimyar/wp-content/plugins/code-snippets/js/utils/hooks.ts
import { createContext, useContext } from 'react' import type { Context } from 'react' export const createContextHook =
(name: string): [ Context
, () => T ] => { const contextValue = createContext
(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] }