Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const Messages: FC = () => {
const handleSubscription = (
messages: MessageEntry[] = [],
response: MessageResponse
) => [response.newMessages, ...messages];
const [res] = useSubscription(
{ query: NewMessageSubQuery },
handleSubscription
);
if (res.error !== undefined) {
return {res.error.message};
}
if (res.data === undefined) {
return <p>No new messages</p>;
}
return (
<ul>
{res.data.map(notif => (
</ul>
export const Home: FC = () => {
const handleSubscription = (
notifications: NotificationResponse[],
notification: NotificationResponse
) => [...notifications, notification];
const [subscription] = useSubscription<
NotificationResponse,
NotificationResponse[]
>({ query: NotificationSubQuery }, handleSubscription);
if (subscription.error) {
return {subscription.error.message};
}
return subscription.data.map(notif => (
));
};