-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor useHideOnScroll value into a context
So that we wouldn't have to call the hook for different components. Removes unnecessary calculations and delays in trigger animation as a result.
- Loading branch information
Showing
7 changed files
with
47 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import useHideOnScroll from "@/lib/hooks/useHideOnScroll"; | ||
import { ReactNode, createContext, useContext } from "react"; | ||
|
||
const ScrollContext = createContext<boolean | undefined>(undefined); | ||
|
||
export const useScrollContext = () => { | ||
const context = useContext(ScrollContext); | ||
if (!context) { | ||
return; | ||
} | ||
return context; | ||
}; | ||
|
||
interface ScrollProviderProps { | ||
children: ReactNode; | ||
} | ||
export const ScrollProvider = (props: ScrollProviderProps) => { | ||
const { children } = props; | ||
const show = useHideOnScroll(); | ||
|
||
return ( | ||
<ScrollContext.Provider value={show}>{children}</ScrollContext.Provider> | ||
); | ||
}; |
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
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