usePollState

This is the hook containing most of the important properties from the PollState. It also provides several other utilities that make it easier to handle the UI for polls.

The full extent of the Poll state can be found here, under the PollState type. If the properties from the hook are not enough for rendering their desired UI, integrators are encouraged to write their own selectors and use the usePollStateStore hook instead.

This hook can only be used within a child of PollContext.

It is highly recommended that the user familiarizes themselves with the Poll client documentation in order to understand the properties better.

Return type

The usePollState hook returns an object containing values from the PollState.

allowAnswers

A property depicting whether answers (comments) are allowed to the poll.

Type
booleanundefined

allowUserSuggestedOptions

A property depicting whether user option suggestions are allowed to the poll.

Type
booleanundefined

answersCount

A property containing the number of answers (comments) to the poll.

Type
number

createdBy

A property containing information about the user who created the poll. Its type can be found here under UserResponse.

This property will be null for anonymous polls.

Type
objectnull

enforceUniqueVote

A property depicting whether each user should have only one and unique vote or they would be able to vote multiple times during the lifespan of a poll.

Type
boolean

isClosed

A property depicting whether the poll is still open for voting or not.

Type
boolean

latestVotesByOption

A property containing the latest votes for each option stored in an object by option ID. Only the last 10 votes are maintained here. If all votes are needed for an option, the usePollOptionVotesPagination hook should be used instead.

This property is not available for anonymous polls.

Type
Record<string, PollVote>

maxVotesAllowed

A property containing the maximum number of votes allowed per user.

Type
number

maxVotedOptionIds

An array of Poll option IDs of all of the options with the maximum number of votes in it. Will only contain more than 1 ID if there’s a tie between options.

Type
string[]

name

A property depicting the name of the poll.

Type
string

options

A property that is a list of all of the options a poll has. A poll cannot have more than 100 options.

Type
PollOption[]

ownAnswer

A property containing the answer (comment) of a user to the current poll. Only one answer can be provided by a single user. This property will not be present in anonymous polls.

Type
PollAnswerundefined

ownVotesByOptionId

A property containing the current user’s own votes in a given poll, stored in an object by option ID.

Type
Record<string, PollVote>

voteCountsByOption

A property containing the vote counts in a given poll, stored in an object by option ID.

Type
Record<string, number>

votingVisibility

A property depicting the visibility of votes in a given poll. It conforms to the VotingVisibility enum found here.

Type
VotingVisibilityundefined
© Getstream.io, Inc. All Rights Reserved.