【问题标题】:Using Material UI in React On Rails在 React On Rails 中使用 Material UI
【发布时间】:2017-09-03 16:01:17
【问题描述】:

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

一切正常,只是模块RaisedButton不能使用,

每次我尝试导入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 中的错误?

【问题讨论】:

  • 你能展示你的布局文件吗?
  • @Panther 你主要DOM ?
  • 您的rails 布局文件。
  • @Panther 我已经更新了我的代码,你想要吗?
  • 页面加载或执行某些操作后立即出现错误?

标签: ruby-on-rails reactjs material-ui react-on-rails


【解决方案1】:

我想我找到了问题所在, 我看到了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键ref,我删除ref,就不会出现错误了。

【讨论】:

  • 你能打开一个issue到material-ui github仓库吗?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 1970-01-01
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2020-03-22
相关资源
最近更新 更多