Skip to content

Instantly share code, notes, and snippets.

@aquinq
Last active December 2, 2024 10:56
import React, { useMemo, useReducer } from 'react';
import useTimeout from '../hooks/use-timeout';
import Upcoming from '../components/upcoming';
import Started from '../components/started';
type MeetingProps = {
startsAt: Date;
};
const Meeting = ({ startsAt }: MeetingProps) => {
const [, rerender] = useReducer((n) => n + 1, 0);
const now = new Date();
const isUpcoming = now.getTime() < startsAt.getTime();
const delay = useMemo(() => {
const diff = startsAt.getTime() - now.getTime();
return diff > 0 ? diff : null;
}, [startsAt.getTime()]);
useTimeout(rerender, delay);
return isUpcoming ? <Upcoming /> : <Started />;
};
export default Meeting;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment