Skip to content

Commit 8afc014

Browse files
committed
test: add a test case for ProfileScreen component using no-unnecessary-use-effect rule
1 parent 920ced2 commit 8afc014

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-unnecessary-use-effect.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,5 +945,27 @@ ruleTester.run(RULE_NAME, rule, {
945945
}, [])
946946
}
947947
`,
948+
tsx`
949+
function ProfileScreen({ navigation, route }) {
950+
const [value, onChangeText] = React.useState(route.params.title);
951+
952+
React.useEffect(() => {
953+
navigation.setOptions({
954+
title: value === '' ? 'No title' : value,
955+
});
956+
}, [navigation, value]);
957+
958+
return (
959+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
960+
<TextInput
961+
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
962+
onChangeText={onChangeText}
963+
value={value}
964+
/>
965+
<Button title="Go back" onPress={() => navigation.goBack()} />
966+
</View>
967+
);
968+
}
969+
`,
948970
],
949971
});

0 commit comments

Comments
 (0)