calcom/lib/hooks/useTheme.tsx
Heaust Azure 521be467a4
resolved typescript problems for success.tsx, useTheme.tsx and event.ts (#786)
* resolved typescript problems for success.tsx, useTheme.tsx and event.ts

* remove NextRouter inferred type

Co-authored-by: Alex Johansson <alexander@n1s.se>

* remove router query inferred type

Co-authored-by: Alex Johansson <alexander@n1s.se>

* URIcomponent change ternary

Co-authored-by: Alex Johansson <alexander@n1s.se>

* infer types for event type

* completed requested changes

* Update pages/success.tsx | change context type to proper

Co-authored-by: Alex Johansson <alexander@n1s.se>

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Alex Johansson <alexander@n1s.se>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
2021-10-05 23:53:24 +01:00

24 lines
606 B
TypeScript

import { Maybe } from "@trpc/server";
import { useEffect, useState } from "react";
// makes sure the ui doesn't flash
export default function useTheme(theme?: Maybe<string>) {
const [isReady, setIsReady] = useState(false);
useEffect(() => {
setIsReady(true);
if (!theme) {
return;
}
if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.classList.add("dark");
} else if (!theme) {
/** Uncovered case */
} else {
document.documentElement.classList.add(theme);
}
}, []);
return {
isReady,
};
}