Skip to content

Support array of objects in style property #2239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacobrask opened this issue Sep 25, 2014 · 5 comments
Closed

Support array of objects in style property #2239

jacobrask opened this issue Sep 25, 2014 · 5 comments

Comments

@jacobrask
Copy link

As proposed in React Future, it would be nice to support a list of style objects in the style property. The objects would be automatically merged (in order, with the last object overriding the previous one).

var boxStyle = {
  padding: 10,
  background: "hotpink"
};
var bixBoxStyle = {
  margin: 10,
  width: 300
};

<div style={boxStyle} />
<div style={[boxStyle, bigBoxStyle]} />
<div style={[boxStyle, bigBoxStyle, {background: "navy"}]} />
@SanderSpies
Copy link
Contributor

Duplicate of: #2196

@phtn
Copy link

phtn commented May 22, 2017

<div style={ Object.assign( {}, boxStyle, bigBoxStyle, {background: "navy"} ) }>

this should merge declared styles as well as specific in-line style like background.
background in boxStyle will be overwritten in this order of Object assignment.

@quantuminformation
Copy link

What is the preferred way to do it today?

@jsu93
Copy link

jsu93 commented Aug 1, 2018

@agustind
Copy link

agustind commented Jan 11, 2019

You can use the spread operator

style={{...styles.box, ...styles.bigBox}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants