Skip to content

Commit

Permalink
support for eslint-plugin-react-hooks (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
donavon authored Feb 21, 2019
1 parent 416b8f8 commit cf65a8a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"extends": "amex"
"extends": "amex",
"plugins": ["react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 2
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
A custom [React Hook](https://reactjs.org/docs/hooks-overview.html) to help you implement a "dark mode" component for your application.
The user setting persists to `localStorage`.

❤️ it? ⭐️ it on [GitHub](https://github.com/donavon/use-dark-mode/stargazers).
❤️ it? ⭐️ it on [GitHub](https://github.com/donavon/use-dark-mode/stargazers)
or [Tweet](https://twitter.com/intent/tweet?text=Check%20out%20the%20useDarkMode%20custom%20React%20Hook%20that%20simplifies%20adding%20a%20persistent%20dark%20mode%20setting%20to%20your%20app.&url=https%3A%2F%2Fgithub.com%2Fdonavon%2Fuse-dark-mode&via=donavon&hashtags=reactjs,hooks,darkmode)
about it.

[![npm version](https://badge.fury.io/js/use-dark-mode.svg)](https://badge.fury.io/js/use-dark-mode) [![Build Status](https://travis-ci.com/donavon/use-dark-mode.svg?branch=master)](https://travis-ci.com/donavon/use-dark-mode) [![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors)
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Check%20out%20the%20useDarkMode%20custom%20React%20Hook%20that%20simplifies%20adding%20a%20persistent%20dark%20mode%20setting%20to%20your%20app.&url=https%3A%2F%2Fgithub.com%2Fdonavon%2Fuse-dark-mode&via=donavon&hashtags=reactjs,hooks,darkmode)

![usedarkmode-small](https://user-images.githubusercontent.com/887639/51113468-079ee100-17d0-11e9-8a35-e29b12b74740.gif)

Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"tag": "latest"
},
"version": "2.3.0",
"version": "2.3.1",
"description": "A custom React Hook to help you implement a \"dark mode\" component.",
"main": "dist/use-dark-mode.js",
"umd:main": "dist/use-dark-mode.umd.js",
Expand Down Expand Up @@ -41,6 +41,7 @@
"babel-jest": "^23.6.0",
"eslint": "^5.10.0",
"eslint-config-amex": "^9.0.0",
"eslint-plugin-react-hooks": "^1.2.0",
"jest": "^23.6.0",
"jest-dom": "^3.0.0",
"microbundle": "^0.9.0",
Expand Down
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import useEventListener from '@use-it/event-listener';

import initialize from './initialize';

const ONCE = [];

const useDarkMode = (
initialValue = false,
{
Expand All @@ -31,7 +29,7 @@ const useDarkMode = (

const stateChangeCallback = useMemo(
() => onChange || getDefaultOnChange(element, classNameDark, classNameLight),
[onChange, element, classNameDark, classNameLight]
[onChange, element, classNameDark, classNameLight, getDefaultOnChange]
);

// Call the onChange handler
Expand All @@ -48,9 +46,9 @@ const useDarkMode = (

return {
value: state,
enable: useCallback(() => setState(true), ONCE),
disable: useCallback(() => setState(false), ONCE),
toggle: useCallback(() => setState(current => !current), ONCE),
enable: useCallback(() => setState(true), [setState]),
disable: useCallback(() => setState(false), [setState]),
toggle: useCallback(() => setState(current => !current), [setState]),
};
};

Expand Down

0 comments on commit cf65a8a

Please sign in to comment.