Files
outline/app/components/Session.js
T
Tom Moor 41028eda4d wip
2021-02-20 15:27:35 -08:00

29 lines
716 B
JavaScript

// @flow
import * as React from "react";
import useStickyState from "../hooks/useStickyState";
type Props = {|
children: React.Node,
|};
export default function Session({ children }: Props) {
const ref = React.useRef(false);
const [, setPreviousSession] = useStickyState<string>("", "previous-session");
const [currentSession, setCurrentSession] = useStickyState<string>(
"",
"current-session"
);
React.useEffect(() => {
if (!ref.current) {
if (currentSession) {
setPreviousSession(currentSession);
}
setCurrentSession(new Date().toISOString());
ref.current = true;
}
}, [setCurrentSession, setPreviousSession, currentSession]);
return children;
}