diff --git a/.eslintrc.js b/.eslintrc.js index c86b6f8434..5a1f5eff8d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,10 +3,11 @@ module.exports = { extends: [ 'eslint:recommended', 'plugin:react/recommended', + 'plugin:react-hooks/recommended', 'plugin:jest/recommended', ], parser: 'babel-eslint', - plugins: ['react', 'react-native', 'detox'], + plugins: ['react', 'react-hooks', 'react-native', 'detox'], parserOptions: { ecmaVersion: 6, sourceType: 'module', diff --git a/app/views/ExposureHistory/ExposureHistory.js b/app/views/ExposureHistory/ExposureHistory.js index 8d9ed2f8fc..cec5d8c091 100644 --- a/app/views/ExposureHistory/ExposureHistory.js +++ b/app/views/ExposureHistory/ExposureHistory.js @@ -35,18 +35,18 @@ export const ExposureHistoryScreen = ({ navigation }) => { fetchData(); + const handleBackPress = () => { + navigation.goBack(); + return true; + }; + BackHandler.addEventListener('hardwareBackPress', handleBackPress); // teardown code return () => { BackHandler.removeEventListener('hardwareBackPress', handleBackPress); }; - }, []); - - const handleBackPress = () => { - navigation.goBack(); - return true; - }; + }, [navigation]); const hasExposure = history?.length && history.some(h => h.exposureMinutes > 0); diff --git a/app/views/Settings.js b/app/views/Settings.js index bfa29be41c..ed04d1dc33 100644 --- a/app/views/Settings.js +++ b/app/views/Settings.js @@ -33,12 +33,11 @@ export const SettingsScreen = ({ navigation }) => { navigation.goBack(); }; - const handleBackPress = () => { - backToMain(); - return true; - }; - useEffect(() => { + const handleBackPress = () => { + navigation.goBack(); + return true; + }; BackHandler.addEventListener('hardwareBackPress', handleBackPress); // TODO: this should be a service or hook @@ -52,7 +51,7 @@ export const SettingsScreen = ({ navigation }) => { return () => { BackHandler.removeEventListener('hardwareBackPress', handleBackPress); }; - }, []); + }, [navigation]); const locationToggleButtonPressed = async () => { try { diff --git a/package.json b/package.json index e42c4dd9be..ffd50b7aa0 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "eslint": "^6.8.0", "eslint-plugin-detox": "^1.0.0", "eslint-plugin-jest": "^23.8.2", + "eslint-plugin-react-hooks": "^4.0.0", "husky": "^4.2.3", "i18next-parser": "tstirrat/i18next-parser#guard-plural-rule", "import-sort-config": "^6.0.0", diff --git a/yarn.lock b/yarn.lock index 6582115f1e..48520b7e71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3596,6 +3596,11 @@ eslint-plugin-react-hooks@^2.0.1: resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.5.1.tgz#4ef5930592588ce171abeb26f400c7fbcbc23cd0" integrity sha512-Y2c4b55R+6ZzwtTppKwSmK/Kar8AdLiC2f9NADCuxbcTgPPg41Gyqa6b9GppgXSvCtkRw43ZE86CT5sejKC6/g== +eslint-plugin-react-hooks@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.0.0.tgz#81196b990043cde339e25c6662aeebe32ac52d01" + integrity sha512-YKBY+kilK5wrwIdQnCF395Ya6nDro3EAMoe+2xFkmyklyhF16fH83TrQOo9zbZIDxBsXFgBbywta/0JKRNFDkw== + eslint-plugin-react-native-globals@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/eslint-plugin-react-native-globals/-/eslint-plugin-react-native-globals-0.1.2.tgz#ee1348bc2ceb912303ce6bdbd22e2f045ea86ea2"