Skip to main content

Variables, State & Props

Skyle automatically transfers the component's class properties to the underlying StyleSheet, allowing styling based on state, props and more! You can access them by using a function inside the sheet as shown below.

...
@styled
class MyComponent extends Component {
styles = styles;
state = {
value: 0,
};
fontSize = 30;
render() {
const { value } = this.state;
return (
<>
<Button onPress={() => this.setState({ value: value + 1 })} title='Click me!' />
<Text style={this.styles.text}></Text>
</>
);
}
}
// Use Skyle's StyleSheet with a function to access class properties!
const styles = StyleSheet.create((o) => {
text: {
fontSize: o.fontSize;
color: o.state.value > 10 ? 'red' : 'green',
}
});