mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(use-theme): body css would bug out on navigation
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { isAllView, isSubscriptionsView } from '../lib/utils/view-utils';
|
||||
import useThemeStore from '../stores/use-theme-store';
|
||||
import determineInitialTheme from './use-initial-theme';
|
||||
import useInitialTheme from './use-initial-theme';
|
||||
|
||||
const useTheme = (): [string, (theme: string) => void] => {
|
||||
const location = useLocation();
|
||||
@@ -20,14 +20,18 @@ const useTheme = (): [string, (theme: string) => void] => {
|
||||
load();
|
||||
}, [loadThemes]);
|
||||
|
||||
const initialTheme = determineInitialTheme();
|
||||
const initialTheme = useInitialTheme();
|
||||
|
||||
const [theme, setLocalTheme] = useState(initialTheme);
|
||||
|
||||
useEffect(() => {
|
||||
const previousTheme = document.body.className;
|
||||
document.body.classList.add(initialTheme);
|
||||
return () => {
|
||||
document.body.classList.remove(initialTheme);
|
||||
if (previousTheme) {
|
||||
document.body.classList.add(previousTheme);
|
||||
}
|
||||
};
|
||||
}, [initialTheme]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user