Hiyve Components - v1.0.0
    Preparing search index...
    • Hook for managing local poll state with Map-based storage.

      Parameters

      • OptionalinitialPolls: Poll[]

        Optional initial polls to populate state

      Returns UsePollStateResult

      Poll state and management functions

      This hook provides efficient O(1) lookup for polls by ID while also maintaining sorted arrays for display. It tracks user votes separately to enable quick lookup of voting status.

      State Management:

      • Polls are stored in a Map for O(1) access by ID
      • Sorted arrays are derived via useMemo for efficient rendering
      • User votes are tracked in a separate Map for quick lookup
      function PollsComponent() {
      const {
      polls,
      sortedPolls,
      activePolls,
      endedPolls,
      userVotes,
      addPoll,
      updatePoll,
      recordVote,
      hasVoted,
      } = usePollState();

      const handleVote = (pollId: string, optionIds: string[]) => {
      recordVote(pollId, optionIds);
      };
      }