How to combine multiple inline style objects?

后端 未结 17 1571
难免孤独
难免孤独 2020-11-28 18:54

In React you can clearly create an object and assign it as an inline style. i.e.. mentioned below.

var divStyle = {
          


        
17条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 19:51

    For ones that looking this solution in React, If you want to use the spread operator inside style, you should use: babel-plugin-transform-object-rest-spread.

    Install it by npm module and configure your .babelrc as such:

    {
      "presets": ["env", "react"],
      "plugins": ["transform-object-rest-spread"]
    }
    

    Then you can use like...

    const sizing = { width: 200, height: 200 }
     

    More info: https://babeljs.io/docs/en/babel-plugin-transform-object-rest-spread/

提交回复
热议问题