Skip to content

Instantly share code, notes, and snippets.

@ide
Created January 14, 2016 23:48
Show Gist options
  • Save ide/81b3317239fc3b613054 to your computer and use it in GitHub Desktop.
Save ide/81b3317239fc3b613054 to your computer and use it in GitHub Desktop.
Applying styles to children
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',
},
});
@weicool
Copy link

weicool commented Jan 15, 2016

Thanks, @ide!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment