We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent edfc22c commit 0dd8bcdCopy full SHA for 0dd8bcd
packages/vue3/src/usePoll.ts
@@ -0,0 +1,33 @@
1
+import { ReloadOptions, VoidFunction } from '@inertiajs/core'
2
+import { router } from '@inertiajs/vue3'
3
+import { onMounted, onUnmounted } from 'vue'
4
+
5
+export default function usePoll(interval: number, options: ReloadOptions, startOnMount = true): VoidFunction {
6
+ let stopFunc: VoidFunction
7
8
+ let stop = () => {
9
+ if (stopFunc) {
10
+ stopFunc()
11
+ }
12
13
14
+ let start = () => {
15
+ stop()
16
+ stopFunc = router.poll(interval, options)
17
18
19
+ onMounted(() => {
20
+ if (startOnMount) {
21
+ start()
22
23
+ })
24
25
+ onUnmounted(() => {
26
27
28
29
+ return {
30
+ stop,
31
+ start,
32
33
+}
0 commit comments