OptionalinitialQuestions: Question[]Optional initial questions to populate the state
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 firstvotes: Questions with most upvotes firstunanswered: Unanswered questions first, then by votesPinned 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>
);
}
Hook for managing local Q&A state with sorting capabilities.