Skip to content

Instantly share code, notes, and snippets.

@johnfmorton
Created February 20, 2017 22:33
Show Gist options
  • Save johnfmorton/d1993d869132f41943a835a175d5477a to your computer and use it in GitHub Desktop.
Save johnfmorton/d1993d869132f41943a835a175d5477a to your computer and use it in GitHub Desktop.
Merging a dynamic style with a predefined style in a React app
class InfoPanel extends React.Component {
// a pre-defined style
scrollBarStyle = {
top: 0,
position: 'absolute',
width: '18px',
height: 54,
background: '#434344'
}
.... code excluded for clarity....
render() {
return (
<div className="scrollBarHolder" style={this.scrollBarHolderStyle}>
{/* NOTE TO SELF: I needed to merge the existing style with one updated property ... set my Motion in this case */}
<div className="scrollBar" style={ Object.assign( {}, this.scrollBarStyle, {transform: `translateY(${this.state.scrollBarOffset}px)`} )}></div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment