I created a custom component:
import React from 'react';
import {View, StyleSheet, TouchableOpacity} from 'react-native';
const Square = ({size, color, onPress, children}) => {
return (
<TouchableOpacity onPress={onPress}>
<View style={styles.sqr}>{children}</View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
sqr: {
width: this.size,
height: this.size,
backgroundColor: this.color,
...
},
});
export default Square;
As you can see above in the sqr
style, I try to use the size
and color
passed in via props
.
I use the Square
in another component in following way:
<Square size={30} color="black" .../>
However the size and color are not applied when run my app.
So, how can I use passed in values in styles of custom component?