usePollTypes()
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.nullif 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>
);
};Last updated