# Polls

A `Poll` instance holds the reactive state of a poll.

## Initialization

Polls of loaded messages are added automatically by `channel.watch()`, `client.queryChannelsAndHydrate()` and `client.queryThreadsAndHydrate()`. Call `registerSubscriptions()` once, so polls follow votes and updates.

```js label="JavaScript"
client.polls.registerSubscriptions();

// A poll that isn't loaded yet: fetches it
const poll = await client.polls.getPoll(pollId);
```

## Reading

```js label="JavaScript"
// A loaded poll, `undefined` if it isn't loaded
const pollInstance = client.polls.fromState(pollId);

const { name, options, vote_counts_by_option, ownVotesByOptionId, is_closed } =
  pollInstance?.state.getLatestValue() ?? {};
```

Subscribe to render changes:

```js label="JavaScript"
const unsubscribe = pollInstance?.state.subscribeWithSelector(
  (state) => ({ vote_counts_by_option: state.vote_counts_by_option }),
  ({ vote_counts_by_option }) => renderVotes(vote_counts_by_option),
);
```

---

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/javascript/state-polls/](https://getstream.io/chat/docs/javascript/state-polls/).