mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 05:10:36 +08:00
31 lines
720 B
TypeScript
31 lines
720 B
TypeScript
import type { FC } from 'react'
|
|
import { createContext, useRef } from 'react'
|
|
import { createLastRunStore } from './store'
|
|
|
|
type LastRunStoreApi = ReturnType<typeof createLastRunStore>
|
|
|
|
type LastRunContextType = LastRunStoreApi | undefined
|
|
|
|
export const LastRunContext = createContext<LastRunContextType>(undefined)
|
|
|
|
type LastRunProviderProps = {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
const LastRunProvider: FC<LastRunProviderProps> = ({
|
|
children,
|
|
}) => {
|
|
const storeRef = useRef<LastRunStoreApi>()
|
|
|
|
if (!storeRef.current)
|
|
storeRef.current = createLastRunStore()
|
|
|
|
return (
|
|
<LastRunContext.Provider value={storeRef.current!}>
|
|
{children}
|
|
</LastRunContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default LastRunProvider
|