react-perfect-dark-mode
Installation
You must first install perfect-dark-mode
into the <head>
of your document.
yarn add react-perfect-dark-mode
Usage
In a component you can use the hook:
import React from 'react'
import { usePerfectDarkMode } from 'react-perfect-dark-mode'
export const Toggle = () => {
const { mode, updateMode } = usePerfectDarkMode()
return (
<button
style={{ visibility: mode !== undefined ? 'visible' : 'hidden' }}
onClick={() =>
updateMode(
(mode, modes, modeIndex) => modes[(modeIndex + 1) % modes.length],
)
}
>
{mode}
</button>
)
}