Skip to content

Commit

Permalink
Make onSessionStart and onSessionEnd props optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillkurko committed Nov 2, 2022
1 parent 7cd73f0 commit d9bb98f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/SessionStatsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const sessionStatsContext = createContext<SessionStats>({

type Props = {
children: ReactNode;
onSessionStart: (stats: SessionStats) => void;
onSessionEnd: (stats: SessionStats) => void;
onSessionStart?: (stats: SessionStats) => void;
onSessionEnd?: (stats: SessionStats) => void;
}

const SessionStatsProvider = ({ children, onSessionStart, onSessionEnd }: Props) => {
Expand All @@ -35,7 +35,7 @@ const SessionStatsProvider = ({ children, onSessionStart, onSessionEnd }: Props)
const stats = persistedStats ? JSON.parse(persistedStats) : sessionStats

setSessionStats(stats)
onSessionStart(stats);
onSessionStart?.(stats);
}

const handleSessionEnd = () => {
Expand All @@ -54,7 +54,7 @@ const SessionStatsProvider = ({ children, onSessionStart, onSessionEnd }: Props)
JSON.stringify(updatedSessionStats),
);

onSessionEnd({
onSessionEnd?.({
...updatedSessionStats,
sessionDuration,
});
Expand Down

0 comments on commit d9bb98f

Please sign in to comment.