Skip to content

Commit cfe2ebd

Browse files
committed
refactor: improve color modes handling
1 parent f399a30 commit cfe2ebd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/App.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ const Page500 = React.lazy(() => import('./views/pages/page500/Page500'))
1616

1717
const App = () => {
1818
const { isColorModeSet, setColorMode } = useColorModes('coreui-free-react-admin-template-theme')
19-
const theme = useSelector((state) => state.theme)
19+
const storedTheme = useSelector((state) => state.theme)
2020

2121
useEffect(() => {
2222
const urlParams = new URLSearchParams(window.location.href.split('?')[1])
23-
if (urlParams.get('theme')) {
24-
setColorMode(urlParams.get('theme'))
23+
const theme = urlParams.get('theme').match(/^[A-Za-z0-9\s]+/)[0]
24+
if (theme) {
25+
setColorMode(theme)
2526
}
2627

2728
if (isColorModeSet()) {
2829
return
2930
}
3031

31-
setColorMode(theme)
32+
setColorMode(storedTheme)
3233
}, []) // eslint-disable-line react-hooks/exhaustive-deps
3334

3435
return (

0 commit comments

Comments
 (0)