Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-2139] demo top nav #165

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move window size to useEffect
  • Loading branch information
plin-stytch committed Jun 3, 2024
commit 2e981a80af488ff889345319c2fbe2e10a254619
16 changes: 12 additions & 4 deletions components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import stytchLogo from '/public/stytch-logo.svg';
import Link from 'next/link';

function NavBar() {
const [windowInnerWidth, setWindowInnerWidth] = React.useState<number>(window.innerWidth);
addEventListener('resize', () => {
setWindowInnerWidth(window.innerWidth);
});
const [windowInnerWidth, setWindowInnerWidth] = React.useState<number>(0);

React.useEffect(() => {
const handleWindowResize = () => {
setWindowInnerWidth(window.innerWidth);
};
handleWindowResize();
window.addEventListener('resize', handleWindowResize);
// unsubscribe from the event on component unmount
return () => window.removeEventListener('resize', handleWindowResize);
}, []);

return (
<div style={styles.container}>
<div style={styles.leftNav}>
Expand Down
Loading