-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CurrentSubjectContext with errors
- Loading branch information
1 parent
3e1aad8
commit b3986af
Showing
5 changed files
with
63 additions
and
16 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
browser/create-template/templates/nextjs-site/src/app/context/CurrentSubjectContext.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,39 @@ | ||
import { env } from '@/env'; | ||
import { createContext, useContext, useState } from 'react'; | ||
|
||
interface CurrentSubjectContextType { | ||
currentSubject: string; | ||
setCurrentSubject: (newSubject: string) => void; | ||
} | ||
|
||
const CurrentSubjectContext = createContext< | ||
CurrentSubjectContextType | undefined | ||
>(undefined); | ||
|
||
export const CurrentSubjectProvider = ({ | ||
children, | ||
}: { | ||
children: Readonly<React.ReactNode>; | ||
}) => { | ||
const [currentSubject, setCurrentSubject] = useState<string>( | ||
env.NEXT_PUBLIC_WEBSITE_RESOURCE, | ||
); | ||
return ( | ||
<CurrentSubjectContext.Provider | ||
value={{ | ||
currentSubject, | ||
setCurrentSubject, | ||
}} | ||
> | ||
{children} | ||
</CurrentSubjectContext.Provider> | ||
); | ||
}; | ||
|
||
export const useCurrentSubject = () => { | ||
const context = useContext(CurrentSubjectContext); | ||
if (!context) { | ||
throw new Error('useSubject must be used within a SubjectProvider'); | ||
} | ||
return context; | ||
}; |
Empty file.
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
20 changes: 12 additions & 8 deletions
20
browser/create-template/templates/nextjs-site/src/views/FullPage/FullPageView.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
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