diff --git a/web/utils/context.spec.ts b/web/utils/context.spec.ts index 40f39dda6a3..ca9816cd762 100644 --- a/web/utils/context.spec.ts +++ b/web/utils/context.spec.ts @@ -6,7 +6,7 @@ import { renderHook } from '@testing-library/react' * and automatic error handling when context is used outside of its provider. * * Two variants are provided: - * - createCtx: Standard React context using useContext/createContext + * - createCtx: Standard React context using React's use/createContext * - createSelectorCtx: Context with selector support using use-context-selector library */ import * as React from 'react' diff --git a/web/utils/context.ts b/web/utils/context.ts index 6afd6131c70..7f4cbda81b7 100644 --- a/web/utils/context.ts +++ b/web/utils/context.ts @@ -1,9 +1,11 @@ import type { Context, Provider } from 'react' -import { createContext, useContext } from 'react' +import { createContext, use } from 'react' import * as selector from 'use-context-selector' +type UseContextImpl = (context: Context) => T + const createCreateCtxFunction = ( - useContextImpl: typeof useContext, + useContextImpl: UseContextImpl, createContextImpl: typeof createContext, ) => { return function({ name, defaultValue }: CreateCtxOptions = {}): CreateCtxReturn { @@ -39,9 +41,9 @@ type CreateCtxReturn = [Provider, () => T, Context] & { // example // const [AppProvider, useApp, AppContext] = createCtx() -export const createCtx = createCreateCtxFunction(useContext, createContext) +export const createCtx = createCreateCtxFunction(use, createContext) export const createSelectorCtx = createCreateCtxFunction( - selector.useContext, + selector.useContext as UseContextImpl, selector.createContext as typeof createContext, )