refactor: extract dark theme to recoil state

This commit is contained in:
Sam 2022-12-22 15:43:10 +01:00
parent d3eaaaaa9d
commit 07c6bf53a9
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 7 additions and 2 deletions

View File

@ -5,11 +5,12 @@ import Link from "next/link";
import NavItem from "./NavItem";
import Logo from "./logo";
import { useRecoilState } from "recoil";
import { userState } from "../lib/state";
import { themeState, userState } from "../lib/state";
import { fetchAPI, APIError, ErrorCode, MeUser } from "../lib/api-fetch";
export default function Navigation() {
const [user, setUser] = useRecoilState(userState);
const [darkTheme, setDarkTheme] = useRecoilState(themeState);
useEffect(() => {
if (user) return;
@ -28,7 +29,6 @@ export default function Navigation() {
);
}, [user, setUser]);
const [darkTheme, setDarkTheme] = useState<boolean>(false);
const [showMenu, setShowMenu] = useState(false);
useEffect(() => {

View File

@ -5,3 +5,8 @@ export const userState = atom<MeUser | null>({
key: "userState",
default: null,
});
export const themeState = atom<boolean>({
key: "themeState",
default: false,
});