You need to make a few adjustments to get this working.
First, import react-dom.
import ReactDOM from 'react-dom';
Second, add the componentDidMount lifecycle method before the render method in your component. This uses react-dom to grab the select element by way of a ref you supply named 'dropdown', then uses jQuery method noted by Sanath above.
componentDidMount() {
var element = ReactDOM.findDOMNode(this.refs.dropdown)
$(element).ready(function() {
$('select').material_select();
});
}
render() {
...
Third, add the code to your component. Also, note:
- 'selected' was removed from the first option element,
- a ref named 'dropdown' was added to the select element,
- className is used instead of class (it's a React thing).
render() {
return (
<div className="input-field col s12">
<select ref="dropdown" defaultValue="1">
<option value="" disabled>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>
</div>
);
}
Last, if you're using webpack, you need to use the webpack.ProvidePlugin to point some specific methods at jQuery.
var webpack = require("webpack");
module.exports = {
...
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"Hammer": "hammerjs/hammer",
createDayLabel: "jquery",
createWeekdayLabel: "jquery",
activateOption: "jquery",
leftPosition: "jquery"
})
]
Reload webpack / server and you're good to go.