Created
January 14, 2016 23:48
-
-
Save ide/81b3317239fc3b613054 to your computer and use it in GitHub Desktop.
Applying styles to children
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { | |
StyleSheet, | |
} from 'react-native'; | |
export default class ChildStyler extends React.Component { | |
render() { | |
return ( | |
<View {...this.props}> | |
{React.Children.map(this.props.children, child => React.cloneElement(child, { | |
style: [child.props.style, styles.customChildStyle], | |
}))} | |
</View> | |
); | |
} | |
} | |
let styles = StyleSheet.create({ | |
customChildStyle: { | |
background: 'blue', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, @ide!