How to use materialize-css with React?

后端 未结 13 1811
太阳男子
太阳男子 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:16

    Inorder to address the concern of bundle size, the easiest way to use it is as follows:

    1. Include the CDN links in your index.html file
    2. Initialize M in your React Component's constructor this.M = window.M
    3. All the other required initializations in case of Modals and other Materialize Components can be done as mentioned in their Documentation using this.M
    4. I like to do those initialization in the componentDidMount lifecycle method.
    5. When unmounting i.e. inside componentWillUnmount, i use the destroy() method on the instances of initialized Materialize Components.

提交回复
热议问题