-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak "How it Works" section's styles and reveal animation
- Loading branch information
1 parent
61705da
commit c6c2966
Showing
4 changed files
with
90 additions
and
64 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,10 @@ | ||
export function debounce<T extends (...args: any[]) => void>( | ||
func: T, | ||
wait: number | ||
): (...args: Parameters<T>) => void { | ||
let timeout: ReturnType<typeof setTimeout>; | ||
return function (...args: Parameters<T>) { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func(...args), wait); | ||
}; | ||
} |
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,36 @@ | ||
import { useLayoutEffect, useState } from "react"; | ||
import { debounce } from "../../helpers/debounce"; | ||
|
||
export function useWindowSize(debounceTime?: number) { | ||
const [size, setSize] = useState<{ | ||
width: number | null; | ||
height: number | null; | ||
}>({ | ||
width: null, | ||
height: null, | ||
}); | ||
|
||
useLayoutEffect(() => { | ||
const handleResize = () => { | ||
setSize({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}); | ||
}; | ||
|
||
// Set initial size | ||
handleResize(); | ||
|
||
const onResize = debounceTime | ||
? debounce(handleResize, debounceTime) | ||
: handleResize; | ||
|
||
window.addEventListener("resize", onResize); | ||
|
||
return () => { | ||
window.removeEventListener("resize", onResize); | ||
}; | ||
}, []); | ||
|
||
return size; | ||
} |