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

usePolls()

usePolls

The usePolls hook is a custom hook provided by the pollz-react package. It allows you to fetch a paginated list of all polls from the Pollz SDK within a React component.

Parameters

The usePolls hook does not take any parameters.

Return Values

The usePolls hook returns an object with the following properties:

  • polls ({ items: Poll[]; meta: PaginationMeta }): An object containing the list of polls (items) and metadata (meta) about the retrieved polls, including total count, current page, items per page, and total number of pages.

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

Usage

import { usePolls } from 'pollz-react';

const YourComponent = () => {
  const { polls, refetch } = usePolls();

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

  return (
    <div>
      <h2>All Polls</h2>
      {polls.items.map((poll) => (
        <div key={poll.id}>
          <p>{poll.name}</p>
          {/* Render additional poll details */}
        </div>
      ))}
      <button onClick={() => refetch()}>Refetch Polls</button>
    </div>
  );
};

The usePolls hook simplifies the process of fetching and displaying a paginated list of all polls within your React components. Customize the hook based on your application's needs.

PrevioususePoll()NextusePollz()

Last updated 1 year ago