0

我尝试将 Material UI 导入到我的 React On Rails 项目中。

一切正常,只是只有ModuleRaisedButton不能用,

每次我尝试导入RaisedButton时,我都会收到如图所示的错误消息。 在此处输入图像描述 我的代码如下:

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,
});

更新

hello_world/index.html.erb:

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

布局/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>

我该如何解决?或者这只是 React On Rails Gem 中的错误?

4

1 回答 1

0

我想我找到了问题,我看到了node_module/material-ui/RaisedButton/RaisedButton.js文件

 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
          )
        )
      );

在这段代码中,有 Obj key ref,我删除了ref,就不会出现错误了。

于 2017-09-03T20:32:18.377 回答