mirror of
https://github.com/sergeyyarkov/devthread.ru.git
synced 2026-10-11 18:29:10 +03:00
prerender dark theme
This commit is contained in:
parent
876d721877
commit
07764daa62
@ -1 +1,21 @@
|
|||||||
import 'firebase/database';
|
import React from 'react';
|
||||||
|
import 'firebase/database';
|
||||||
|
|
||||||
|
const OnDark = () => {
|
||||||
|
const codeToRunOnClient = `
|
||||||
|
if (localStorage.getItem('dark') || (new Date().getHours() >= 22 || new Date().getHours() <= 6)) {
|
||||||
|
document.body.classList.add('dark')
|
||||||
|
window.localStorage.setItem('dark', 'true')
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<script
|
||||||
|
dangerouslySetInnerHTML={{ __html: codeToRunOnClient }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const onRenderBody = ({ setPreBodyComponents }) => {
|
||||||
|
setPreBodyComponents(<OnDark key='isDarkTheme' />)
|
||||||
|
}
|
||||||
@ -18,8 +18,8 @@ const ThemeProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (localStorage.getItem('dark') || (new Date().getHours() >= 22 || new Date().getHours() <= 6)) {
|
if (localStorage.getItem('dark')) {
|
||||||
toggleDarkTheme()
|
setIsDark(true)
|
||||||
}
|
}
|
||||||
}, [setIsDark])
|
}, [setIsDark])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user