import React, { FC, ReactNode, createContext, useContext, useState, useCallback, } from "react"; import { IMessageWithPendingAndReacts } from "../hooks/useMessages"; export interface IReplyProviderProps { children: ReactNode; } export interface IReplyContextState { replyMessage: Partial | undefined; showReply: (reply: Partial | undefined) => void; hideReply: () => void; } export const ReplyContext = createContext( {} as IReplyContextState ); export const ReplyProvider: FC = ({ children }) => { const [replyMessage, setReplyMessage] = useState< Partial | undefined >(); const hideReply = useCallback( () => setReplyMessage(undefined), [setReplyMessage] ); const showReply = useCallback( (reply: Partial | undefined) => { setReplyMessage(reply); }, [setReplyMessage] ); return ( {children} ); }; export const useReply = () => { const context = useContext(ReplyContext); if (context === undefined) { throw new Error("useReply must be used within a ReplyProvider"); } return context; };