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