mirror of
https://github.com/langgenius/dify.git
synced 2026-07-15 01:17:04 +08:00
Merge remote-tracking branch 'origin/feat/ui-onboarding-rewrite' into feat/agent-v2
This commit is contained in:
@ -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'
|
||||
|
||||
@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user