mirror of
https://github.com/sergeyyarkov/devthread.ru.git
synced 2026-10-11 02:09:04 +03:00
prerender dark theme
This commit is contained in:
parent
876d721877
commit
07764daa62
@ -1 +1,21 @@
|
||||
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(() => {
|
||||
if (localStorage.getItem('dark') || (new Date().getHours() >= 22 || new Date().getHours() <= 6)) {
|
||||
toggleDarkTheme()
|
||||
if (localStorage.getItem('dark')) {
|
||||
setIsDark(true)
|
||||
}
|
||||
}, [setIsDark])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user