Rocket.Chat.ReactNative/app/containers/MessageComposer/hooks/useMessage.ts

21 lines
556 B
TypeScript
Raw Normal View History

2024-01-25 14:11:07 +00:00
import { useEffect, useState } from 'react';
import { IMessage } from '../../../definitions';
import { getMessageById } from '../../../lib/database/services/Message';
// TODO: Not reactive. Should we work on an official version?
export const useMessage = (messageId: string): IMessage | undefined => {
const [message, setMessage] = useState<IMessage>();
useEffect(() => {
const load = async () => {
const result = await getMessageById(messageId);
if (result) {
setMessage(result);
}
};
load();
}, [messageId]);
return message;
};