Hiyve Components - v1.0.0
    Preparing search index...
    • Hook for managing local Q&A state with sorting capabilities.

      Parameters

      • OptionalinitialQuestions: Question[]

        Optional initial questions to populate the state

      Returns UseQAStateResult

      Object containing questions state and manipulation functions

      This hook manages the local state of questions in the Q&A panel. It provides CRUD operations and sorting functionality.

      Sort Modes:

      • newest: Most recently asked questions first
      • votes: Questions with most upvotes first
      • unanswered: Unanswered questions first, then by votes

      Pinned Questions: Pinned questions always appear at the top, regardless of sort mode.

      function MyQAComponent() {
      const {
      questions,
      sortedQuestions,
      sortMode,
      setSortMode,
      addQuestion,
      updateQuestion,
      removeQuestion,
      } = useQAState();

      const handleAsk = (content: string) => {
      addQuestion({
      id: generateId(),
      authorId: 'user-123',
      authorName: 'John Doe',
      content,
      createdAt: Date.now(),
      upvotes: [],
      isAnswered: false,
      isPinned: false,
      });
      };

      return (
      <div>
      {sortedQuestions.map(q => <QuestionCard key={q.id} question={q} />)}
      </div>
      );
      }