Skip to content

Commit 9157af1

Browse files
committed
Update docs
1 parent 74836b0 commit 9157af1

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/rules/no-unused-styles.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Detect unused StyleSheet rules in React components
22
When working on a component over a longer period of time, you could end up with unused StyleSheet rules that slipt in over time but are forgotten as you continue to improve your UX/UI design.
33

4-
The following patterns are considered warnings:
4+
The following patterns are considered warnings:
55

66
```js
77
const styles = StyleSheet.create({
@@ -55,6 +55,44 @@ const Hello = React.createClass({
5555
}
5656
});
5757
```
58+
Style rules referenced in a conditional and logical expressions are marked as used.
59+
60+
```js
61+
const styles = StyleSheet.create({
62+
name: {}
63+
});
64+
65+
const Hello = React.createClass({
66+
getInitialState: function() {
67+
return {condition: true};
68+
},
69+
70+
render: function() {
71+
return <Text textStyle={[this.state.condition && styles.name]}>
72+
Hello {this.props.name}
73+
</Text>;
74+
}
75+
});
76+
```
77+
78+
```js
79+
const styles = StyleSheet.create({
80+
name: {},
81+
alternate: {},
82+
});
83+
84+
const Hello = React.createClass({
85+
getInitialState: function() {
86+
return {condition: true};
87+
},
88+
89+
render: function() {
90+
return <Text textStyle={[this.state.condition ? styles.name : styles.alternate]}>
91+
Hello {this.props.name}
92+
</Text>;
93+
}
94+
});
95+
```
5896
Rules are also marked as used when they are used in tags that contain the word `style`.
5997

6098
```js

0 commit comments

Comments
 (0)