📊
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
  • useAnonymousPoll
  • Parameters
  • Return Values
  • Usage
  1. Tooling
  2. React

useAnonymousPoll()

useAnonymousPoll

The useAnonymousPoll hook is a custom hook provided by the pollz-react package. It allows you to fetch an anonymous poll using the provided poll token from the Pollz SDK within a React component.

Parameters

pollToken (string)

  • The poll token for the anonymous poll you want to fetch.

Return Values

The useAnonymousPoll hook returns an object with the following properties:

  • poll (PollWithOptions | null): The fetched anonymous poll object. null if the poll is still loading.

  • refetch (function): A function to manually refetch the anonymous poll data.

Usage

import { useAnonymousPoll } from 'pollz-react';

const YourComponent = ({ pollToken }) => {
  const { poll, refetch } = useAnonymousPoll(pollToken);

  if (!poll) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h2>Anonymous Poll</h2>
      <p>{poll.name}</p>
      {/* Render additional anonymous poll details */}
      <button onClick={() => refetch()}>Refetch Anonymous Poll</button>
    </div>
  );
};
PrevioususePollTypes()

Last updated 1 year ago