How to use materialize-css with React?

后端 未结 13 1827
太阳男子
太阳男子 2020-12-07 17:52

I have a Meteor/React project, using ES6 modules. I\'ve installed materialize-css using npm, but I\'m not sure how to actually use the Materialize classes in my JSX code. Wh

13条回答
  •  悲哀的现实
    2020-12-07 18:29

    There are possible ways that I can recommend to use:

    1. One way is just include your stylesheet file in index.html and use className property in your React components just like this.

          var myDivElement = 
      ; ReactDOM.render(myDivElement, document.getElementById('example'));
    2. Another way is to bundle all your stylesheeets in one stylesheet file and to use them as previous one.

    3. One option could be to use webpack. By using webpack, it is possible to use embedded stylesheets in jsx files just by requiring stylesheet that you want to include.

      require("./stylesheet.css")

      To examine in detail webpack stylesheet option: http://webpack.github.io/docs/stylesheets.html

    4. Also see JedWatson's classnames repo for conditional className usage. https://github.com/JedWatson/classnames

提交回复
热议问题