Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): use React use for context helper (#37289)

lmlm7ec295fd6624
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 = <T>(context: Context<T>) => T
+
const createCreateCtxFunction = (
- useContextImpl: typeof useContext,
+ useContextImpl: UseContextImpl,
createContextImpl: typeof createContext,
) => {
return function<T>({ name, defaultValue }: CreateCtxOptions<T> = {}): CreateCtxReturn<T> {
@@ -39,9 +41,9 @@ type CreateCtxReturn<T> = [Provider<T>, () => T, Context<T>] & {
// example
// const [AppProvider, useApp, AppContext] = createCtx<AppContextValue>()
-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,
)