How do you add multiple browser specific values into a CSS style in React?

久未见 提交于 2019-12-02 01:09:31

If you want to use inline styles and also get vendor prefixing, you can use a library like Radium to abstract the vendor prefixing for you.

By adding a @Radium decorator to your component, Radium will hook into the styles you pass to the component and automatically manage and prefix them.

var Radium = require('radium');
var React = require('react');

@Radium
class Grabby extends React.Component {
  render() {
    return (
      <div style={style}>
        {this.props.children}
      </div>
    );
  }
}

var style = {
  cursor: "grab" // this will get autoprefixed for you!
};

The best you could do is to create a css class with the cursor attribute, and add it to your component

.container {
  height: 10px;
  width: 10px;
}

.grab {
  cursor: -moz-grab,
  cursor: -webkit-grab,
  cursor: grab,
}

Then in your react component:

var isGrabEnabled = true;

<div className={['container', (isGrabEnabled ? 'grab' : '')]}>Grab me!</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!