> ## Documentation Index
> Fetch the complete documentation index at: https://inertiajs.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Polling

<Warning>You are viewing the documentation for Inertia.js v2. Inertia.js v3 has been released and is now the default version. Please visit the [upgrade guide](/v3/getting-started/upgrade-guide) to get started.</Warning>

## Poll Helper

Polling your server for new information on the current page is common, so Inertia provides a poll helper designed to help reduce the amount of boilerplate code. In addition, the poll helper will automatically stop polling when the page is unmounted.

The only required argument is the polling interval in milliseconds.

<CodeGroup>
  ```js Vue icon="vuejs" theme={null}
  import { usePoll } from '@inertiajs/vue3'

  usePoll(2000)
  ```

  ```jsx React icon="react" theme={null}
  import { usePoll } from '@inertiajs/react'

  usePoll(2000)
  ```

  ```js Svelte icon="s" theme={null}
  import { usePoll } from '@inertiajs/svelte'

  usePoll(2000)
  ```
</CodeGroup>

If you need to pass additional request options to the poll helper, you can pass any of the `router.reload` options as the second parameter.

<CodeGroup>
  ```js Vue icon="vuejs" theme={null}
  import { usePoll } from '@inertiajs/vue3'

  usePoll(2000, {
      onStart() {
              console.log('Polling request started')
      },
      onFinish() {
              console.log('Polling request finished')
      }
  })
  ```

  ```jsx React icon="react" theme={null}
  import { usePoll } from '@inertiajs/react'

  usePoll(2000, {
      onStart() {
              console.log('Polling request started')
      },
      onFinish() {
              console.log('Polling request finished')
      }
  })
  ```

  ```js Svelte icon="s" theme={null}
  import { usePoll } from '@inertiajs/svelte'

  usePoll(2000, {
      onStart() {
              console.log('Polling request started')
      },
      onFinish() {
              console.log('Polling request finished')
      }
  })
  ```
</CodeGroup>

If you'd like more control over the polling behavior, the poll helper provides `stop` and `start` methods that allow you to manually start and stop polling. You can pass the `autoStart: false` option to the poll helper to prevent it from automatically starting polling when the component is mounted.

<CodeGroup>
  ```vue Vue icon="vuejs" theme={null}
  <script setup>
  import { usePoll } from '@inertiajs/vue3'

  const { start, stop } = usePoll(2000, {}, {
      autoStart: false,
  })
  </script>

  <template>
      <button @click="start">Start polling</button>
      <button @click="stop">Stop polling</button>
  </template>
  ```

  ```jsx React icon="react" theme={null}
  import { usePoll } from '@inertiajs/react'

  export default () => {
      const { start, stop } = usePoll(2000, {}, {
              autoStart: false,
      })

      return (
              <div>
                      <button onClick={start}>Start polling</button>
                      <button onClick={stop}>Stop polling</button>
              </div>
      )
  }
  ```

  ```js Svelte icon="s" theme={null}
  import { usePoll } from '@inertiajs/svelte'

  const { start, stop } = usePoll(2000, {}, {
      autoStart: false,
  })
  ```
</CodeGroup>

## Throttling

By default, the poll helper will throttle requests by 90% when the browser tab is in the background. If you'd like to disable this behavior, you can pass the `keepAlive` option to the poll helper.

<CodeGroup>
  ```js Vue icon="vuejs" theme={null}
  import { usePoll } from '@inertiajs/vue3'

  usePoll(2000, {}, {
      keepAlive: true,
  })
  ```

  ```jsx React icon="react" theme={null}
  import { usePoll } from '@inertiajs/react'

  usePoll(2000, {}, {
      keepAlive: true,
  })
  ```

  ```js Svelte icon="s" theme={null}
  import { usePoll } from '@inertiajs/svelte'

  usePoll(2000, {}, {
      keepAlive: true,
  })
  ```
</CodeGroup>
