Skip to content

Commit

Permalink
fix refresh with rapid change 'feature'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpepler committed Sep 4, 2024
1 parent 3aadd53 commit 2ed316d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
"use client";

import { createExcuse } from "@/util/createExcuse";
import styles from "./page.module.css";
import { useEffect, useState } from "react";
export default function Home() {
const [excuse, setExcuse] = useState(createExcuse());

const newExcuse = () => setExcuse(createExcuse());

useEffect(() => {
if (typeof window !== "undefined") {
window.addEventListener("beforeunload", newExcuse);
return () => window.removeEventListener("beforeunload", newExcuse);
}
}, []);

return (
<main className={styles.main}>
<h1>i cant come to the office today because</h1>
<h1>{createExcuse()}.</h1>
<h1 suppressHydrationWarning>{excuse}.</h1>
</main>
);
}

0 comments on commit 2ed316d

Please sign in to comment.