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

# shouldPollFlow

> Decide whether to read a Flow payment again with the JavaScript SDK, because it can still change without any action from your page.

Tells you whether a flow can still change without any action from your page, which means your page should read it again with [`getFlow`](https://www.dynamic.xyz/docs/javascript/reference/client/get-flow). `shouldPollFlow` makes no request; it checks the flow you pass.

It returns `false` when the flow:

* has ended: `executionState` is `cancelled`, `expired`, or `failed`, or `settlementState` is `completed` or `failed`.
* waits for the payer: `executionState` is `initiated` or `source_attached`. Only an action from your page moves the flow on, and the function you call returns the updated flow.

An exchange payment is the exception. A flow in `source_attached` with an exchange source waits for the exchange to confirm the payment, so `shouldPollFlow` returns `true`.

In every other state, including `quoted`, `signing`, `broadcasted`, `source_detected`, and `source_confirmed`, it returns `true`. A state added in a later version is treated the same way, so a flow is not left unwatched.

## Usage

```javascript theme={"system"}
import { getFlow, shouldPollFlow } from '@dynamic-labs-sdk/client';

let flow = await getFlow({ flowId: 'your-flow-id' });

while (shouldPollFlow({ flow })) {
  await new Promise((resolve) => setTimeout(resolve, 3000));
  flow = await getFlow({ flowId: 'your-flow-id' });
}
```

## Parameters

| Parameter | Type | Description |
| - | - | - |
| `flow` | `Flow` | The flow, as last read with `getFlow` or returned by a Flow function. |

## Returns

`boolean`: `true` while the flow can still change on its own, and `false` once it has ended or while it waits for the payer.

`shouldPollFlow` does not set an interval. The React hooks read the flow every 3 seconds while it returns `true`.

## Notes

A flow that waits for the payer is not read again, so the page does not notice when it expires. Run a timer on `flow.expiresAt` and read the flow when it fires, as shown in [Build a custom payment UI](https://www.dynamic.xyz/docs/javascript/reference/flow-ui-guide.md#expiry-timer).

## React

`useGetFlow` and `useSubscribeToFlowStateChange` already use `shouldPollFlow` to decide when to refetch. You do not need to call it yourself in React.

## Related

* [`getFlow`](https://www.dynamic.xyz/docs/javascript/reference/client/get-flow): read the flow.
* [Build a custom payment UI](https://www.dynamic.xyz/docs/javascript/reference/flow-ui-guide.md#load-and-route-by-phase): load the flow and keep it current.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.