shellphone.app/app/messages/hooks/use-conversation.ts

21 lines
389 B
TypeScript
Raw Normal View History

import { useQuery } from "blitz";
2021-07-31 22:33:18 +08:00
import getConversationsQuery from "../queries/get-conversations";
2021-07-31 22:33:18 +08:00
export default function useConversation(recipient: string) {
return useQuery(
getConversationsQuery,
{},
{
select(conversations) {
2021-09-25 07:12:16 +08:00
if (!conversations?.[recipient]) {
return null;
2021-07-31 22:33:18 +08:00
}
return conversations[recipient]!;
2021-07-31 22:33:18 +08:00
},
2021-08-01 15:40:18 +08:00
keepPreviousData: true,
2021-08-01 20:04:04 +08:00
},
);
2021-07-31 22:33:18 +08:00
}