Skip to content

Instantly share code, notes, and snippets.

View Elvincth's full-sized avatar
🚀
Hey

Elvin Chu Elvincth

🚀
Hey
View GitHub Profile
@Elvincth
Elvincth / useBeforeUnload.ts
Created May 8, 2024 10:04
Add the "Changes you made may not be saved" warning to a Next.js app
import { Router } from "next/router";
import { useCallback, useEffect } from "react";
export const useBeforeUnload = (
enabled: boolean | (() => boolean) = true,
message = "Changes you made may not be saved.",
) => {
const handler = useCallback(
(event: BeforeUnloadEvent) => {
const finalEnabled = typeof enabled === "function" ? enabled() : true;
@Elvincth
Elvincth / test.model.ts
Created August 22, 2022 10:22
mongoose-paginate-v2 typescript usage
schema.plugin(paginate);
export const CourseModel: PaginateModel<ICourse> =
(models.Course as PaginateModel<ICourse>) ||
model<ICourse, PaginateModel<ICourse>>("Course", schema);