mharj-react-dark
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

react-dark

Dark Mode context API based on prefers-color-scheme

Install

npm i mharj-react-dark

Provider setup

ReactDOM.render(
	<DarkModeProvider>
		<App />
	</DarkModeProvider>,
	document.getElementById('root'),
);

Provider can have initialValue={true/false} attribute

usage as HOC

use direct DarkModeConsumer, or

withDarkMode wrapper

class SomeComponent extends React.Component<WithDarkMode> {
	public render() {
		return <>Dark Mode: {this.props.isDarkMode ? 'true' : 'false'}</>;
	}
}

export default withDarkMode(App);

usage as Hook

useDarkMode

export const SomeComponent: React.FC = () => {
	const {isDarkMode} = useDarkMode();
	return <>Dark Mode: {isDarkMode ? 'true' : 'false'}</>;
};

Readme

Keywords

Package Sidebar

Install

npm i mharj-react-dark

Weekly Downloads

4

Version

0.0.3

License

MIT

Unpacked Size

12.4 kB

Total Files

7

Last publish

Collaborators

  • mharj