# CreatePollContext

`CreatePollContext` is provided by [`CreatePoll`](/chat/docs/sdk/react-native/v8/ui-components/create-poll/). If you are not familiar with the React Context API, see the [React docs](https://reactjs.org/docs/context.html).

`CreatePollContext` must be used within [`Channel`](/chat/docs/sdk/react-native/v8/core-components/channel/) because it depends on [`MessageInputContext`](/chat/docs/sdk/react-native/v8/contexts/message-input-context/) provided there.

## Best Practices

- Use `useCreatePollContext` inside `Channel`-scoped poll creation flows only.
- Validate poll options before calling `createAndSendPoll`.
- Use `closePollCreationDialog` to cleanly dismiss the UI.
- Keep creation UI responsive; avoid heavy logic in render.
- Treat context values as the source of truth for poll draft state.

## Basic Usage

Consume `CreatePollContext` in any child of `Channel`:

```tsx
import { useContext } from "react";
import { CreatePollContext } from "stream-chat-react-native";

const value = useContext(CreatePollContext);
```

Alternatively, use the `useCreatePollContext` hook.

```tsx
import { useCreatePollContext } from "stream-chat-react-native";

const value = useCreatePollContext();
```

## Value

### sendMessage

Sends a composed message within `MessageInput` component to channel. This function is attached to `onPress` handler of [`SendButton`](/chat/docs/sdk/react-native/v8/core-components/channel#sendbutton/). The message optimistically gets added to message list UI first, before actually making API call to server.
During this intermediate stage, MessageStatus component will display an indicator for "pending" state.

| Type     |
| -------- |
| Function |

The function takes an object as a parameter with the following properties:

| Parameter      | Description                                                        |
| -------------- | ------------------------------------------------------------------ |
| `localMessage` | Contains the message data that will be shown in the UI immediately |
| `message`      | Contains the data that will be sent to the backend                 |
| `options`      | Contains options for sending/updating the message                  |


### `closePollCreationDialog`

A method that will be used as a callback whenever the default `CreatePoll` component back button is pressed in the header. Unless used, it will have no effect if the default `CreatePollContent` is overridden.

| Type         |
| ------------ |
| `() => void` |

### `createAndSendPoll`

A method that will be used as a callback whenever send button is clicked on the `CreatePoll` modal. If a custom UI is used for `CreatePollContent`, it can be used as an out-of-the-box method to create and send a poll to the `MessageList`.

It expects to receive an argument that conforms to the `CreatePollData` type that can be found [here](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts).

| Type                                          |
| --------------------------------------------- |
| `(pollData: CreatePollData) => Promise<void>` |

### `createPollOptionHeight`

A property used to define the height of the poll options in the `CreatePollContent` draggable list. The items can have a constant and equal height only and this should only be used if custom theming implies that the static height of the items changes. Has no effect if a custom UI for `CreatePollContent` is provided.

| Type   |
| ------ |
| number |


---

This page was last updated at 2026-04-17T17:33:45.126Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/react-native/v8/contexts/create-poll-context/](https://getstream.io/chat/docs/sdk/react-native/v8/contexts/create-poll-context/).