Since I use CSS Modules, importing materialize css would scope it to that particular component. So I did the following
Step 1) install materialise
npm install materialize-css@next
Step 2) in index.html
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-alpha.3/css/materialize.min.css">
Step 3) import materialise.js in whichever component its needed
for e.g. in SomeComponent.js (for e.g. if this is about a sidenav)
import React from 'react';
import M from 'materialize-css';
....
// ref can only be used on class components
class SomeComponent extends Component {
// get a reference to the element after the component has mounted
componentDidMount(){
M.Sidenav.init(this.sidenav);
}
render(){
return (
<ul className={this.props.classes}
ref={ (sidenav) => {this.sidenav = sidenav} }
id={this.props.id}>
// menuItems
</ul>
)
}
}
just a beginner, so I would appreciate any comments on downsides of this method
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…