useSystemColorMode()
npm i react-use-system-color-mode
A React hook for retrieving the system color mode. It is SSR compatible, built with TypeScript and listens to live changes of the system preference.
Quick Start
Check out the example on CodeSandbox
import { useSystemColorMode } from 'react-use-system-color-mode'
const Example = () => {
const colorMode = useColorMode();
return (
<div>
<h2>Your color Mode is {colorMode}</h2>
</div>
);
};
API
useSystemColorMode()
Returns the current color mode of the users OS. Returns dark
or light
. On the server it always returns dark
.
'dark' | 'light'
Returns Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Johannes Klauss - @JohannesKlauss - klauss.johannes@gmail.com
Project Link: https://github.com/JohannesKlauss/react-use-system-color-mode
Prior Art
Basis of this package is the react-use-color-mode which is not maintained anymore.