diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-04-05 18:07:12 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-04-05 18:08:22 +0200 |
commit | cd048f198ceb9be961d31232b8169dd15c3c320e (patch) | |
tree | 9a54be3dbb0ab0a89fb2577228cfcadb820828e4 | |
parent | Fix author profile link in blog (diff) | |
download | blog-cd048f198ceb9be961d31232b8169dd15c3c320e.tar.gz blog-cd048f198ceb9be961d31232b8169dd15c3c320e.tar.zst blog-cd048f198ceb9be961d31232b8169dd15c3c320e.zip |
Fix useActiveSection
-rw-r--r-- | src/components/ActiveSectionProvider.tsx | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/components/ActiveSectionProvider.tsx b/src/components/ActiveSectionProvider.tsx index 0d491ac..bc6d111 100644 --- a/src/components/ActiveSectionProvider.tsx +++ b/src/components/ActiveSectionProvider.tsx | |||
@@ -26,9 +26,11 @@ const ActiveSectionContext = createContext<ActiveSection | undefined>( | |||
26 | export function useActiveSection(): ActiveSection { | 26 | export function useActiveSection(): ActiveSection { |
27 | const value = useContext(ActiveSectionContext); | 27 | const value = useContext(ActiveSectionContext); |
28 | if (value === undefined) { | 28 | if (value === undefined) { |
29 | throw new Error( | 29 | // Return fallback instead of signalling an error to avoid crashes in dev mode. |
30 | 'useActiveSection is only valid inside ActiveSectionProvider', | 30 | return { |
31 | ); | 31 | hash: undefined, |
32 | setHash: () => {}, | ||
33 | } | ||
32 | } | 34 | } |
33 | return value; | 35 | return value; |
34 | } | 36 | } |