Spaces:
Configuration error
Configuration error
Download frontend/src/context/conversation-context.tsx from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 938 Bytes
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/context/conversation-context.tsx
- Command line
-
hf download hf://spaces/flyingdarkdev/README/frontend/src/context/conversation-context.tsx
-
curl -L -o conversation-context.tsx https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/context/conversation-context.tsx
938 Bytes
| import React, { useMemo } from "react"; | |
| import { useParams } from "react-router"; | |
| interface ConversationContextType { | |
| conversationId: string; | |
| } | |
| const ConversationContext = React.createContext<ConversationContextType | null>( | |
| null, | |
| ); | |
| export function ConversationProvider({ | |
| children, | |
| }: { | |
| children: React.ReactNode; | |
| }) { | |
| const { conversationId } = useParams<{ conversationId: string }>(); | |
| if (!conversationId) { | |
| throw new Error( | |
| "ConversationProvider must be used within a route that has a conversationId parameter", | |
| ); | |
| } | |
| const value = useMemo(() => ({ conversationId }), [conversationId]); | |
| return <ConversationContext value={value}>{children}</ConversationContext>; | |
| } | |
| export function useConversation() { | |
| const context = React.useContext(ConversationContext); | |
| if (!context) { | |
| throw new Error( | |
| "useConversation must be used within a ConversationProvider", | |
| ); | |
| } | |
| return context; | |
| } | |