Using Material UI in React On Rails

764 views Asked by At

I tried to import Material UI into my React On Rails Project.

Everything is okay, but just only Module RaisedButton can't use,

Every time I try to import RaisedButton, I will get the error message like the picture. enter image description here My code is below:

import ReactOnRails from 'react-on-rails';
import PropTypes from 'prop-types';
import React from 'react';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import RaisedButton from 'material-ui/RaisedButton'; 

const App = () => (
    <MuiThemeProvider>
        <RaisedButton label="hi"/>
    </MuiThemeProvider>
)

ReactOnRails.register({
  App,
});

UPDATE

hello_world/index.html.erb:

<h1>Hello World</h1>
<%= react_component("App", props: @hello_world_props, prerender: false) %>

layouts/hello_world.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <title>ReactOnRailsWithWebpacker</title>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'webpack-bundle' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

How can I fix it ? Or It's just the bug in React On Rails Gem?

1

There are 1 answers

1
Champer Wu On

I think I find the problem, I see the node_module/material-ui/RaisedButton/RaisedButton.js file

 return _react2.default.createElement(
        _Paper2.default,
        {
          className: className,
          style: (0, _simpleAssign2.default)(styles.root, style),
          zDepth: this.state.zDepth
        },
        _react2.default.createElement(
          _EnhancedButton2.default,
          (0, _extends3.default)({}, other, buttonEventHandlers, {
            ref: 'container',
            disabled: disabled,
            style: (0, _simpleAssign2.default)(styles.button, buttonStyle),
            focusRippleColor: mergedRippleStyles.color,
            touchRippleColor: mergedRippleStyles.color,
            focusRippleOpacity: mergedRippleStyles.opacity,
            touchRippleOpacity: mergedRippleStyles.opacity
          }),
          _react2.default.createElement(
            'div',
            {
              ref: 'overlay',
              style: prepareStyles((0, _simpleAssign2.default)(styles.overlay, overlayStyle))
            },
            enhancedButtonChildren
          )
        )
      );

In this code, there is the Obj key ref, I delete the ref, and the error would not appears.