簡體   English   中英

在React On Rails中使用Material UI

[英]Using Material UI in React On Rails

我試圖將Material UI導入我的React On Rails項目中。

一切正常,但只有Module 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) %>

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>

我該如何解決? 還是僅僅是React On Rails Gem中的錯誤?

我想我找到了問題,我看到了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 ,並且不會出現錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM