> For the complete documentation index, see [llms.txt](https://pollz.gitbook.io/pollz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pollz.gitbook.io/pollz/tooling/react/usepoll.md).

# usePoll()

## `usePoll`&#x20;

The `usePoll` hook is a custom hook provided by the `pollz-react` package. It allows you to fetch and manage real-time updates for a specific poll from the Pollz SDK within a React component.

### Parameters

#### `pollId` (EntryIdType)

* The unique identifier of the poll you want to fetch and listen to updates for.

#### `options` (optional)

An object with the following optional properties:

* `listen` (boolean): Whether to set up a real-time listener for updates. Default is `false`.
* `orderOptionsBy` (OrderBy): The order in which to retrieve poll options for the updated poll. Default is `OrderBy.Asc` (ascending).

### Return Values

The `usePoll` hook returns an object with the following properties:

* `poll` (PollWithOptions | null): The fetched poll object. `null` if the poll is still loading.
* `refetch` (function): A function to manually refetch the poll data.

### Example

```jsx
const YourComponent = ({ pollId }) => {
  const { poll, refetch } = usePoll(pollId, { listen: true, orderOptionsBy: OrderBy.Asc });

  if (!poll) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h2>{poll.name}</h2>
      {/* Render your poll component with poll data */}
      <button onClick={() => refetch()}>Refetch Poll</button>
    </div>
  );
};
```

The `usePoll` hook provides an easy way to integrate specific poll data into your React components, with support for real-time updates. Customize the hook based on your application's needs.
