1

Let's say this is your SCSS:

.someclass {
  background: red;
  height: 1500px;
  width: 10000px;
}

And this is how you use it:

import React, { Component, PropTypes } from 'react'
import ReactDropZone from 'react-dropzone'
import ReactDOM from 'react-dom'
import withStyles from 'isomorphic-style-loader/lib/withStyles'
import s from './ImageTool.scss'

class ImageTool extends Component {

  render() {

    return (

      <div className={s.someclass}></div>

    )

  }

}

export default withStyles(ImageTool, s)

So this works well.

Now what happens if you need to name your class some-class? Clearly className={s.some-class} doesn't work, and neither does className={s.someClass} (nothing happens).

4

1 回答 1

5

JSX 中花括号之间的代码只是 JavaScript,s只是一个对象。即,您可以s像在 JS 中一样访问属性,即使它们包含破折号、空格或其他有趣的字符。

具体来说,你可以写:

<div className={s['some-class']}></div>
于 2016-06-30T02:46:01.617 回答