mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-04-25 11:54:35 +00:00
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m13s
24 lines
751 B
TypeScript
24 lines
751 B
TypeScript
import {createContext, ReactNode, RefObject, useContext, useRef} from 'react'
|
|
|
|
type CommentFormContext = {
|
|
commentFormRef?: RefObject<HTMLTextAreaElement | null>
|
|
focusCommentForm: () => void
|
|
}
|
|
|
|
export const CommentFormContext = createContext<CommentFormContext | null>(null)
|
|
|
|
export const useCommentFormContext = () => useContext(CommentFormContext)
|
|
|
|
export default function CommentFormProvider({children}: { children: ReactNode }) {
|
|
const commentFormRef = useRef<HTMLTextAreaElement>(null)
|
|
|
|
const focusCommentForm = () => {
|
|
commentFormRef.current?.focus()
|
|
}
|
|
|
|
return (
|
|
<CommentFormContext.Provider value={{commentFormRef, focusCommentForm}}>
|
|
{children}
|
|
</CommentFormContext.Provider>
|
|
)
|
|
} |