Skip to content

Instantly share code, notes, and snippets.

@oojr
Last active May 5, 2017 03:11
Show Gist options
  • Save oojr/50a51cbca796453a04ba2b1b2d11121d to your computer and use it in GitHub Desktop.
Save oojr/50a51cbca796453a04ba2b1b2d11121d to your computer and use it in GitHub Desktop.
css-in-js example
class Post extends React.Component {
onSponsorPost(){
if(this.props.post.type === 'sponsored'){
return '#F9BF3B' //gold color
}
}
render(){
// web
<div>
<div style={[styles.thumbnail, {backgroundColor: this.onSponsorPost()}]}>
</div>
// react native
<View>
<View style={[styles.thumbnail, {backgroundColor: this.onSponsorPost()}]}>
</View>
}
}
//next.js web framework
const styles = {
thumbnail: {
margin: 5,
padding: 5,
backgroundColor: '#91969A', //grey
borderRadius: 3,
minWidth: 66
}
}
// react native
const styles = StyleSheet.create({
thumbnail: {
margin: 5,
padding: 5,
backgroundColor: '#91969A', //grey
borderRadius: 3,
minWidth: 66
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment