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.

Example usage

import { PollVote, PollState } from "stream-chat";
import { usePollStateStore } from "stream-chat-react-native";

type PollOptionSelectorReturnValue = {
  latestVotesByOption: Record<string, PollVote[]>;
  maxVotedOptionIds: string[];
};

const selector = <
  StreamChatGenerics extends
    DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
  nextValue: PollState<StreamChatGenerics>,
): PollOptionSelectorReturnValue => ({
  latestVotesByOption: nextValue.latestVotesByOption,
  maxVotedOptionIds: nextValue.maxVotedOptionIds,
});

const { latestVotesByOption, maxVotedOptionIds } = usePollStateStore(selector);
© Getstream.io, Inc. All Rights Reserved.