import {createContext, ReactNode, RefObject, useContext, useRef, useState} from 'react' import {Comment} from '@/types'; type CommentFormContext = { commentFormRef?: RefObject focusCommentForm: () => void commentLength: number setCommentLength: (commentLength: number) => void commentMaxLength: number replyTo: Comment | null setReplyTo: (replyTo: Comment | null) => void } export const CommentFormContext = createContext(null) export const useCommentFormContext = () => useContext(CommentFormContext) export default function CommentFormProvider({children}: { children: ReactNode }) { const [replyTo, setReplyTo] = useState(null) const [commentLength, setCommentLength] = useState(0) const commentFormRef = useRef(null) const commentMaxLength = 300 const focusCommentForm = () => { commentFormRef.current?.focus() } return ( {children} ) }