Skip to content

Commit

Permalink
🐛 fix: add startTransition on callback function (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Sep 20, 2023
1 parent 960e444 commit 1b502d1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/factories/createThemeProvider/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ const ThemeObserver: FC<{
setBrowserPrefers: (value: BrowserPrefers) => void;
}> = ({ themeMode, setAppearance, setBrowserPrefers }) => {
const matchBrowserTheme = () => {
if (matchBrowserPrefers('dark').matches) {
setAppearance('dark');
} else {
setAppearance('light');
}
safeStartTransition(() => {
if (matchBrowserPrefers('dark').matches) {
setAppearance('dark');
} else {
setAppearance('light');
}
});
};

const updateBrowserTheme = () => {
if (matchBrowserPrefers('dark').matches) {
setBrowserPrefers('dark');
} else {
setBrowserPrefers('light');
}
safeStartTransition(() => {
if (matchBrowserPrefers('dark').matches) {
setBrowserPrefers('dark');
} else {
setBrowserPrefers('light');
}
});
};

// 自动监听系统主题变更
Expand Down

0 comments on commit 1b502d1

Please sign in to comment.