import * as React from 'react' ; const { useState , useEffect } = React ; interface Result { value : boolean ; enable : ( ) => void ; disable : ( ) => void ; toggle : ( ) => void ; } const className = 'dark-mode' ; const element = document . body ; function useDarkMode ( initialValue = false ) { const [ value , setDarkMode ] = useState ( initialValue ) ; useEffect ( ( ) => { if ( value ) { element . classList . add ( className ) ; } else { element . classList . remove ( className ) ; } } , [ value ] ) ; return { value , enable : ( ) => setDarkMode ( true ) , disable : ( ) => setDarkMode ( false ) , toggle : ( ) => setDarkMode ( current => ! current ) } ; } ; export default useDarkMode ;