hedgedoc/src/hooks/common/use-apply-dark-mode.ts
Tilman Vatteroth 1777ba848f
Collected minor changes from #837 (#962)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
2021-01-23 21:01:53 +00:00

23 lines
607 B
TypeScript

/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { useEffect } from 'react'
import { useIsDarkModeActivated } from './use-is-dark-mode-activated'
export const useApplyDarkMode = (): void => {
const darkModeActivated = useIsDarkModeActivated()
useEffect(() => {
if (darkModeActivated) {
window.document.body.classList.add('dark')
} else {
window.document.body.classList.remove('dark')
}
return () => {
window.document.body.classList.remove('dark')
}
}, [darkModeActivated])
}