How to use materialize-css with React?

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

    I wanted to get materialbox to work and here is how i did it

    import React, { Component } from "react";
    import M from "materialize-css/dist/js/materialize.min.js";
    
    class Image extends Component {
      constructor(props) {
        super(props);
        this.imageRef = React.createRef();
      }
    
      onLoad = () => {
        M.Materialbox.init(this.imageRef.current);
      };
    
      render() {
        return (
          ...
        );
      }
    }
    
    export default Image;
    

    an interesting thing to note - it didnt work when i was trying M.init inside componentDidMount maybe because the image doesnt load by the time the call to componentDidMount is made.

提交回复
热议问题