How to add multiple classes to a ReactJS Component?

后端 未结 29 2176
执念已碎
执念已碎 2020-11-27 09:16

I am new to ReactJS and JSX and I am having a little problem with the code below.

I am trying to add multiple classes to the className attribute on eac

29条回答
  •  自闭症患者
    2020-11-27 09:27

    You can create an element with multiple class names like this, I tryed these both way, its working fine...

    If you importing any css then you can follow this way : Way 1:

    import React, { Component, PropTypes } from 'react';
    import csjs from 'csjs';
    import styles from './styles';
    import insertCss from 'insert-css';
    import classNames from 'classnames';
    insertCss(csjs.getCss(styles));
    export default class Foo extends Component {
      render() {
        return (
          
    { 'text' }
    ); } }

    way 2:

    import React, { Component, PropTypes } from 'react';
    import csjs from 'csjs';
    import styles from './styles';
    import insertCss from 'insert-css';
    import classNames from 'classnames';
    insertCss(csjs.getCss(styles));
    export default class Foo extends Component {
      render() {
        return (
          
    { 'text' }
    ); } }

    **

    If you applying css as internal :

    const myStyle = {
      color: "#fff"
    };
    
    // React Element using Jsx
    const myReactElement = (
      

    Hello World!

    ); ReactDOM.render(myReactElement, document.getElementById("app"));
    .myClassName {
      background-color: #333;
      padding: 10px;
    }
    .myClassName1{
      border: 2px solid #000;
    }
    
    
    

提交回复
热议问题