From 07764daa62e59532545269f503d66dd144531c27 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Mon, 20 Jul 2020 14:02:34 +0300 Subject: [PATCH] prerender dark theme --- gatsby-ssr.js | 22 +++++++++++++++++++++- src/context/ThemeContext.js | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 3cdc25a..dd6ddab 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -1 +1,21 @@ -import 'firebase/database'; \ No newline at end of file +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 ( +