📊
Pollz
  • Introduction
  • Quickstart
  • Guides
    • Initializing your app
    • Create a Poll
    • Vote for a Poll
    • Retrieve a Poll
    • Manage Poll Options
    • Listen to update
    • Anonymous Poll
  • Components
    • React
    • React Native
    • Embedded
  • API Reference
    • init()
    • pollOptions()
      • addOption()
      • deleteOption()
      • renameOption()
    • anonymous
      • createAnonymousToken()
      • getAnonymousPoll()
      • voteAnonymously()
    • polls
      • create()
      • get()
      • getAll()
      • vote()
      • rename()
      • deleteOne()
      • listen()
    • pollTypes
      • getAll()
  • Tooling
    • Typescript
    • React
      • usePoll()
      • usePolls()
      • usePollz()
      • usePollTypes()
      • useAnonymousPoll()
Powered by GitBook
On this page
  1. API Reference
  2. polls

listen()

listen(pollId: EntryIdType, callback: (poll: PollWithOptions) => void, orderOptionsBy = OrderBy.Asc): () => void

Set up a real-time listener for updates to a specific poll.

Parameters:

  • pollId (EntryIdType): The ID of the poll for which to listen to updates.

  • callback ((poll: PollWithOptions) => void): A callback function that will be invoked when the poll is updated. It receives the updated poll object as its parameter.

  • orderOptionsBy (OrderBy, optional): The order in which to retrieve poll options for the updated poll. Default is OrderBy.Asc (ascending).

Returns:

  • A function that can be called to stop listening to updates for the specified poll.

Example:

const pollIdToListen = 1;

const unsubscribe = pollz.polls.listen(pollIdToListen, (updatedPoll) => {
  console.log('Poll Updated:', updatedPoll);
});

// To stop listening
// unsubscribe();

The listen method enables you to set up a real-time listener for updates to a specific poll identified by its unique ID (pollId). Provide a callback function (callback) that will be invoked each time the poll is updated. The callback receives the updated poll object (PollWithOptions) as its parameter.

The method returns a function (unsubscribe) that can be called to stop listening to updates for the specified poll. Call unsubscribe when you no longer need to receive updates.

Note: Ensure that the provided pollId corresponds to an existing poll in the system.

PreviousdeleteOne()NextpollTypes

Last updated 1 year ago