We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
oncePerRefresh
1 parent cb53903 commit 387f330Copy full SHA for 387f330
src/lib/once-per-refresh.ts
@@ -0,0 +1,13 @@
1
+const hasRunSinceTheLastFullPageload = new Set<string>()
2
+
3
+/**
4
+ * This function helps you run a given function only once per full pageload.
5
+ * So this will not run again due to turbolink navigation.
6
+ */
7
+export function oncePerRefresh(key: string, fun: () => void) {
8
+ if (hasRunSinceTheLastFullPageload.has(key)) {
9
+ return
10
+ }
11
+ fun()
12
+ hasRunSinceTheLastFullPageload.add(key)
13
+}
0 commit comments