-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba9ce0b
commit b28fe13
Showing
4 changed files
with
50 additions
and
37 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
apps/sovoli.com/src/app/[username]/[slug]/context/KnowledgeContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import type { SelectKnowledgeSchema } from "@sovoli/db/schema"; | ||
import { createContext, useContext } from "react"; | ||
|
||
export const KnowledgeContext = createContext<SelectKnowledgeSchema | null>( | ||
null, | ||
); | ||
|
||
export const useKnowledge = () => { | ||
const context = useContext(KnowledgeContext); | ||
if (!context) { | ||
throw new Error("useKnowledge must be used within a KnowledgeProvider"); | ||
} | ||
return context; | ||
}; | ||
|
||
export const KnowledgeProvider = ({ | ||
children, | ||
knowledge, | ||
}: { | ||
children: React.ReactNode; | ||
knowledge: SelectKnowledgeSchema; | ||
}) => { | ||
return <KnowledgeContext value={knowledge}>{children}</KnowledgeContext>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters