Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

TocLandingContext.tsx 802 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  1. import { createContext, useContext } from 'react'
  2. export type TocItem = {
  3. fullPath: string
  4. title: string
  5. intro?: string
  6. }
  7. export type TocLandingContextT = {
  8. title: string
  9. introPlainText: string
  10. tocItems: Array<TocItem>
  11. }
  12. export const TocLandingContext = createContext<TocLandingContextT | null>(null)
  13. export const useTocLandingContext = (): TocLandingContextT => {
  14. const context = useContext(TocLandingContext)
  15. if (!context) {
  16. throw new Error('"useTocLandingContext" may only be used inside "TocLandingContext.Provider"')
  17. }
  18. return context
  19. }
  20. export const getTocLandingContextFromRequest = (req: any): TocLandingContextT => {
  21. return {
  22. title: req.context.page.title,
  23. introPlainText: req.context.page.introPlainText,
  24. tocItems: req.context.tocItems || [],
  25. }
  26. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...