Skip to content

Commit a794dbf

Browse files
committed
BREAKING CHANGE: add performance rule to prevent using useIsFocused
1 parent 0fd5627 commit a794dbf

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Save without formatting: [⌘ + K] > [S]
2+
3+
// This should trigger one error breaking eslint-plugin-react-native:
4+
// no-restricted-imports
5+
6+
import { useIsFocused } from "@react-navigation/native";
7+
import { Text } from "react-native";
8+
9+
export const MyComponent = () => {
10+
const isFocused = useIsFocused();
11+
12+
return <Text>{isFocused ? "focused" : "unfocused"}</Text>;
13+
};

example-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"devDependencies": {
1212
"@bam.tech/eslint-plugin": "*",
1313
"@bam.tech/typescript-config": "*",
14+
"@react-navigation/native": "^6.1.18",
1415
"@react-navigation/stack": "^6.4.1",
1516
"@testing-library/react-native": "^12.3.1",
1617
"@types/jest": "^29.5.2",

packages/eslint-plugin/lib/configs/performance.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export const performanceConfig = defineConfig({
1717
message:
1818
'Please use "@react-navigation/native-stack" instead of "@react-navigation/stack".',
1919
},
20+
{
21+
name: "@react-navigation/native",
22+
importNames: ["useIsFocused"],
23+
message:
24+
"Please use useFocusEffect instead of useIsFocused to avoid excessive rerenders.",
25+
},
2026
],
2127
},
2228
],

0 commit comments

Comments
 (0)