mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-30 06:45:47 -04:00
Replace empty components with hooks (#666)
This commit is contained in:
parent
9e9108ec9a
commit
0d2c2fe0ee
5 changed files with 19 additions and 24 deletions
18
src/hooks/common/use-apply-dark-mode.ts
Normal file
18
src/hooks/common/use-apply-dark-mode.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { ApplicationState } from '../../redux'
|
||||
|
||||
export const useApplyDarkMode = ():void => {
|
||||
const darkModeActivated = useSelector((state: ApplicationState) => state.darkMode.darkMode)
|
||||
|
||||
useEffect(() => {
|
||||
if (darkModeActivated) {
|
||||
window.document.body.classList.add('dark')
|
||||
} else {
|
||||
window.document.body.classList.remove('dark')
|
||||
}
|
||||
return () => {
|
||||
window.document.body.classList.remove('dark')
|
||||
}
|
||||
}, [darkModeActivated])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue