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

usePollTypes()

usePollTypes

The usePollTypes hook is a custom hook provided by the pollz-react package. It allows you to fetch and manage the list of available poll types from the Pollz SDK within a React component.

Parameters

The usePollTypes hook does not take any parameters.

Return Values

The usePollTypes hook returns an object with the following properties:

  • pollTypes (PollType[] | null): An array containing the list of available poll types. null if the poll types are still loading.

  • refetch (function): A function to manually refetch the list of poll types.

Usage

import { usePollTypes } from 'pollz-react';

const YourComponent = () => {
  const { pollTypes, refetch } = usePollTypes();

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

  return (
    <div>
      <h2>Poll Types</h2>
      {pollTypes.map((pollType) => (
        <div key={pollType.id}>
          <p>{pollType.name}</p>
          {/* Render additional poll type details */}
        </div>
      ))}
      <button onClick={() => refetch()}>Refetch Poll Types</button>
    </div>
  );
};
PrevioususePollz()NextuseAnonymousPoll()

Last updated 1 year ago