Spaces:
Runtime error
Runtime error
File size: 684 Bytes
a45ece3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
function useSystemPrefersDark(): boolean {
if (typeof window === 'undefined') return false
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
}
function initTheme() {
const saved = localStorage.getItem('cc_theme')
const root = document.documentElement
const prefersDark = useSystemPrefersDark()
const isDark = saved ? saved === 'dark' : prefersDark
root.classList.toggle('dark', isDark)
}
initTheme()
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
) |