import { PollVote, PollState } from "stream-chat";
import { usePollStateStore } from "stream-chat-react-native";
type PollOptionSelectorReturnValue = {
latestVotesByOption: Record<string, PollVote[]>;
maxVotedOptionIds: string[];
};
const selector = (nextValue: PollState): PollOptionSelectorReturnValue => ({
latestVotesByOption: nextValue.latestVotesByOption,
maxVotedOptionIds: nextValue.maxVotedOptionIds,
});
const { latestVotesByOption, maxVotedOptionIds } = usePollStateStore(selector);usePollStateStore
A utility hook used to access the poll state store directly by passing a selector.
The full extent of the Poll state can be found here, under the PollState type.
This hook can only be used within a child of PollContext.
Best Practices
- Use selectors to limit re-renders to only the state you need.
- Keep selectors pure and stable for predictable updates.
- Use this hook only inside
PollContextchildren. - Prefer
usePollStatefor simple cases; use this for advanced state access. - Handle missing or partial poll state gracefully.