-
Notifications
You must be signed in to change notification settings - Fork 132
Closed
Description
when I added the rule for no-unused-styles
to my project I got many errors.
most of them were due to styles dynamically loaded from functions or vars.
consider the following use cases:
class MyView extends Component {
static propTypes = {
isActive: React.PropTypes.bool,
type: React.PropTypes.oneOf(['typeA', 'typeB'])
};
get myActiveStyle() {
return this.props.isActive ? style.active : {}
}
render() {
var typeStyle = styles[this.props.type];
return (
<View style={[this.activeStyle, typeStyle]} / >
);
}
}
// All 3 styles will be marked as unused
const styles = StyleSheet.create({
active: {...},
typeA: {...},
typeB: {...},
})
my current solution is to wrap the erroring code with:
/*eslint-disable react-native/no-unused-styles */
const styles = StyleSheet.create({...});
/*eslint-enable react-native/no-unused-styles */
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels