0

我有两个组件,它们使用相同的布局/样式和不同的内容。我在 React.js 中使用镭。我在其中一个组件中使用了内联样式,并希望对其他组件使用相同的样式。我是 Radium 和 React 的新手。帮帮我!

提前致谢。干杯!!

4

1 回答 1

0

您只需要创建一个共享的外部样式文件,然后将其导入每个需要它的组件中。

// styles.js
export default {
  base: {
    background: 'red'
  }
}

// components
import sharedStyles from 'path/to/styles.js';

@Radium
class Button extends React.Component {
  render() {
    return (
      <button
        style={[
          sharedStyles.base
        ]}>
        {this.props.children}
      </button>
    );
  }
}
于 2017-03-07T02:57:59.120 回答