Hiyve Components - v1.0.0
    Preparing search index...
    • Hook for Q&A synchronization via data messages.

      Parameters

      Returns UseQASyncResult

      Object containing sync functions and connection state

      This hook handles real-time synchronization of Q&A state across all participants in a room using the Hiyve data message system.

      Message Flow:

      • When a user posts a question, it's broadcast to all participants
      • When the owner answers, the answer is broadcast to all
      • When votes change, the new vote array is broadcast
      • Late joiners request state from the owner

      Owner Responsibilities:

      • Responding to state requests from late joiners
      • Answering questions
      • Deleting questions
      • Pinning/unpinning questions
      function QAComponent() {
      const questionsRef = useRef(new Map());
      const [questions, setQuestions] = useState([]);

      const {
      postQuestion,
      answerQuestion,
      deleteQuestion,
      toggleVote,
      pinQuestion,
      connected,
      } = useQASync({
      client,
      isOwner,
      localUserId: userId,
      localUserName: userName,
      questionsRef,
      onStateUpdate: setQuestions,
      });

      const handleAsk = (content) => {
      const question = postQuestion(content);
      if (question) {
      setQuestions(prev => [...prev, question]);
      }
      };
      }