From e4d683e6d80effd0d9db4baeb27fe87a4590f301 Mon Sep 17 00:00:00 2001 From: Michael Fix Date: Tue, 19 Feb 2019 13:09:30 -0800 Subject: [PATCH] fix react hooks linting issues (#679) --- .eslintrc.js | 3 ++- README.md | 2 +- components/RandomImage.js | 4 ++-- components/TweetButton.js | 10 ++++++---- package.json | 2 +- yarn.lock | 8 ++++---- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4eb8573..4ac1044 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -23,7 +23,8 @@ module.exports = { 'import/no-unresolved': 'error', 'no-duplicate-imports': 'error', 'jsx-a11y/click-events-have-key-events': 'off', - 'react-hooks/rules-of-hooks': 'error' + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/reactive-deps': 'error' }, settings: { react: { diff --git a/README.md b/README.md index b7c41f0..1840f9b 100644 --- a/README.md +++ b/README.md @@ -111,5 +111,5 @@ Thanks goes out to all these wonderful people ([emoji key](https://github.com/ke -
briandennis
briandennis

πŸ’» πŸ“– πŸš‡ πŸ‘€
mfix22
mfix22

πŸ’¬ πŸ’» πŸ€”
jakedex
jakedex

πŸ’¬ πŸ’» 🎨 πŸ“Ή
andrewda
andrewda

πŸ’¬ πŸ’» πŸ› πŸ‘€
yeskunall
yeskunall

πŸ’» πŸ“– πŸ”§ πŸ›
stoshfabricius
stoshfabricius

πŸ’»
jkling38
jkling38

πŸ“–
otobrglez
otobrglez

πŸ’»
darahak
darahak

πŸ“–
dom96
dom96

πŸ’»
elrumordelaluz
elrumordelaluz

πŸ’»
cjb
cjb

πŸ’»
Krzysztof-Cieslak
Krzysztof-Cieslak

πŸ’»
fernahh
fernahh

πŸ“–
g3r4n
g3r4n

πŸ’»
Mat Gadd
Mat Gadd

πŸ› πŸ’»
Brad Davies
Brad Davies

πŸ› πŸ’»
Rafael CΓ’mara
Rafael CΓ’mara

πŸ’»
Gleb Bahmutov
Gleb Bahmutov

⚠️ πŸ”§
IvΓ‘n MunguΓ­a
IvΓ‘n MunguΓ­a

πŸ’»
Dillon Mulroy
Dillon Mulroy

πŸ’»
Nihad Abbasov
Nihad Abbasov

πŸ’»
Hugo Torzuoli
Hugo Torzuoli

πŸ“–
Bruno C. Couto
Bruno C. Couto

πŸ’»
Mark Molnar
Mark Molnar

πŸ’»
Takahiko Inayama
Takahiko Inayama

πŸ’»
François Martin
François Martin

πŸ’»
Raphael Amorim
Raphael Amorim

πŸ’»
Camron Flanders
Camron Flanders

πŸ’»
Eric Adamski
Eric Adamski

πŸ’»
Winner Crespo
Winner Crespo

πŸ’» 🎨
Milos
Milos

πŸ’» πŸ”§ πŸ“– 🌍
Yashu Mittal
Yashu Mittal

πŸ’»
Rachel M. Carmena
Rachel M. Carmena

πŸ“–
Miguel Salazar
Miguel Salazar

πŸ“– 🌍
Vyom Jain
Vyom Jain

πŸ“– 🌍
racaljk
racaljk

🌍
Sean
Sean

πŸ’»
Izabela Borges
Izabela Borges

🌍
Shinil M S
Shinil M S

🌍
Berke Atac
Berke Atac

🌍
LEE YONGJUN
LEE YONGJUN

🌍
Matthew Nielsen
Matthew Nielsen

πŸ’»
Boy
Boy

πŸ“¦
Vetrivel Chinnasamy
Vetrivel Chinnasamy

🌍
Farzad YZ
Farzad YZ

πŸ’» πŸ€”
Yannick Loriot
Yannick Loriot

🌍
+
briandennis
briandennis

πŸ’» πŸ“– πŸš‡ πŸ‘€
mfix22
mfix22

πŸ’¬ πŸ’» πŸ€”
jakedex
jakedex

πŸ’¬ πŸ’» 🎨 πŸ“Ή
andrewda
andrewda

πŸ’¬ πŸ’» πŸ› πŸ‘€
yeskunall
yeskunall

πŸ’» πŸ“– πŸ”§ πŸ›
stoshfabricius
stoshfabricius

πŸ’»
jkling38
jkling38

πŸ“–
otobrglez
otobrglez

πŸ’»
darahak
darahak

πŸ“–
dom96
dom96

πŸ’»
elrumordelaluz
elrumordelaluz

πŸ’»
cjb
cjb

πŸ’»
Krzysztof-Cieslak
Krzysztof-Cieslak

πŸ’»
fernahh
fernahh

πŸ“–
g3r4n
g3r4n

πŸ’»
Mat Gadd
Mat Gadd

πŸ› πŸ’»
Brad Davies
Brad Davies

πŸ› πŸ’»
Rafael CΓ’mara
Rafael CΓ’mara

πŸ’»
Gleb Bahmutov
Gleb Bahmutov

⚠️ πŸ”§
IvΓ‘n MunguΓ­a
IvΓ‘n MunguΓ­a

πŸ’»
Dillon Mulroy
Dillon Mulroy

πŸ’»
Nihad Abbasov
Nihad Abbasov

πŸ’»
Hugo Torzuoli
Hugo Torzuoli

πŸ“–
Bruno C. Couto
Bruno C. Couto

πŸ’»
Mark Molnar
Mark Molnar

πŸ’»
Takahiko Inayama
Takahiko Inayama

πŸ’»
François Martin
François Martin

πŸ’»
Raphael Amorim
Raphael Amorim

πŸ’»
Camron Flanders
Camron Flanders

πŸ’»
Eric Adamski
Eric Adamski

πŸ’»
Winner Crespo
Winner Crespo

πŸ’» 🎨
Milos
Milos

πŸ’» πŸ”§ πŸ“– 🌍
Yashu Mittal
Yashu Mittal

πŸ’»
Rachel M. Carmena
Rachel M. Carmena

πŸ“–
Miguel Salazar
Miguel Salazar

πŸ“– 🌍
Vyom Jain
Vyom Jain

πŸ“– 🌍
racaljk
racaljk

🌍
Sean
Sean

πŸ’»
Izabela Borges
Izabela Borges

🌍
Shinil M S
Shinil M S

🌍
Berke Atac
Berke Atac

🌍
LEE YONGJUN
LEE YONGJUN

🌍
Matthew Nielsen
Matthew Nielsen

πŸ’»
Boy
Boy

πŸ“¦
Vetrivel Chinnasamy
Vetrivel Chinnasamy

🌍
Farzad YZ
Farzad YZ

πŸ’» πŸ€”
Yannick Loriot
Yannick Loriot

🌍
diff --git a/components/RandomImage.js b/components/RandomImage.js index 2c6ed06..214d9cd 100644 --- a/components/RandomImage.js +++ b/components/RandomImage.js @@ -42,13 +42,13 @@ function RandomImage(props) { if (cacheIndex === 0 || cacheIndex > cache.length - 2) { updateCache() } - }, [cacheIndex]) + }, [cacheIndex, cache.length, updateCache]) React.useEffect(() => { if (imgs) { cache.push(...imgs) } - }, [imgs]) + }, [cache, imgs]) const loading = updating || selecting diff --git a/components/TweetButton.js b/components/TweetButton.js index 12d4851..437f7d6 100644 --- a/components/TweetButton.js +++ b/components/TweetButton.js @@ -4,10 +4,12 @@ import { useAsyncCallback } from '@dawnlabs/tacklebox' import Button from './Button' function useWindowListener(key, fn) { + const callback = React.useRef(fn) + React.useEffect(() => { - window.addEventListener(key, fn) - return () => window.removeEventListener(key, fn) - }, []) + window.addEventListener(key, callback.current) + return () => window.removeEventListener(key, callback.current) + }, [key, callback]) } function useOnlineListener() { @@ -19,7 +21,7 @@ function useOnlineListener() { ? navigator.onLine : true ) - }, []) + }, [setOnline]) useWindowListener('offline', () => setOnline(false)) useWindowListener('online', () => setOnline(true)) diff --git a/package.json b/package.json index 9de61cf..143ad55 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "eslint-plugin-import": "^2.16.0", "eslint-plugin-jsx-a11y": "^6.2.1", "eslint-plugin-react": "^7.12.3", - "eslint-plugin-react-hooks": "^1.0.1", + "eslint-plugin-react-hooks": "^1.1.0-alpha.1", "husky": "^1.3.1", "lint-staged": "^8.1.3", "now": "^14.0.0", diff --git a/yarn.lock b/yarn.lock index fdf4013..6d90584 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2755,10 +2755,10 @@ eslint-plugin-jsx-a11y@^6.2.1: has "^1.0.3" jsx-ast-utils "^2.0.1" -eslint-plugin-react-hooks@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.0.1.tgz#76b6fb4edafab02eab0090078977687157605dd9" - integrity sha512-yNhvY7EFBp0mq0Bt8BHoS57GwJ4e1qSYdvDFSfPnjmiSmyGUfQFQGcQs4K0JQFDGopWkURWq58psbUJIhWZ2Kg== +eslint-plugin-react-hooks@^1.1.0-alpha.1: + version "1.1.0-alpha.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.1.0-alpha.1.tgz#4df0ee992cee25b6b256beb529aa58478e5dc869" + integrity sha512-mliA3yxdvED1124X883LEqZhry/c30syJ2hMMOHdiWvqgtPNgf8d7waMxUZx72iAHXwGkt/lGDaWkq5+d9Zn6A== eslint-plugin-react@^7.12.3: version "7.12.4"