mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
fix: use hook with first render (#2481)
This commit is contained in:
@@ -4,18 +4,16 @@ import { memo, useRef } from 'react';
|
|||||||
|
|
||||||
const themes = ['dark', 'light'];
|
const themes = ['dark', 'light'];
|
||||||
|
|
||||||
// a workaround to sync theme to electron
|
|
||||||
let firstRender = true;
|
|
||||||
|
|
||||||
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
const lastThemeRef = useRef(theme);
|
const lastThemeRef = useRef(theme);
|
||||||
if (lastThemeRef.current !== theme || firstRender) {
|
const onceRef = useRef(false);
|
||||||
|
if (lastThemeRef.current !== theme || !onceRef.current) {
|
||||||
if (environment.isDesktop && theme) {
|
if (environment.isDesktop && theme) {
|
||||||
window.apis?.ui.handleThemeChange(theme as 'dark' | 'light' | 'system');
|
window.apis?.ui.handleThemeChange(theme as 'dark' | 'light' | 'system');
|
||||||
}
|
}
|
||||||
lastThemeRef.current = theme;
|
lastThemeRef.current = theme;
|
||||||
firstRender = false;
|
onceRef.current = true;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user