import { useContext } from "react";
import { PollContext } from "stream-chat-react-native";
const value = useContext(PollContext);PollContext
PollContext is provided by Poll. If you are not familiar with the React Context API, see the React docs.
PollContext must be used within Channel because it depends on values provided there.
Best Practices
- Use
usePollContextinsideChannel-scoped poll components only. - Treat
pollandmessageas read-only UI state. - Avoid duplicating poll state in local component state.
- Handle missing or stale poll data gracefully.
- Keep poll UI logic lightweight to avoid list re-renders.
Basic Usage
Consume PollContext in any child of Channel:
Alternatively, use the usePollContext hook.
import { usePollContext } from "stream-chat-react-native";
const value = usePollContext();Value
message
Message object.
| Type |
|---|
Message type |
poll *
An instance of the Poll class containing reactive state.
It is used by the underlying usePollContext, usePollStateStore and usePollState hooks to provide us with the reactive Poll state.
If you need the Poll instance you may get it from client.polls.fromState(pollId).
| Type |
|---|
| object |