現在下記のサイトを参考にサンプルアプリを作っています。
Rails 5.1でReact.js連携アプリを構築してみよう
アプリケーションの起動自体はできるのですがmaterial-ui
の表示がうまくいきません(m_ _m)
コンソールで確認してみると
といった表示がでています。
調べると下記のサイトが見つかりreact-tap-event-plugin
は react16.4.0
以降では使えないことがわかりました。
Uncaught TypeError: Cannot read property 'injection' of undefined [closed]
16.4.0
でmaterial-ui
のカードコンポーネントを表示させるには下記のコードをどのように変更すればよろしいでしょうか?
わかる方がいらっしゃれば教えていただきますようよろしくお願いいたします(m_ _m)
###エラー内容
react(rails5との連携)でmaterial-ui
のカードコンポーネントが表示されない
###期待する動作
material-ui(もしくは代替方法)でカードコンポーネントを表示させたい
###動作環境
-
Rails5
-- Ruby:2.5.1
-- Ruby on Rails: 5.1.6 -
React: 16.6.3
-- react-tap-event-plugin: 3.0.3
###参考サイト
Rails 5.1でReact.js連携アプリを構築してみよう
###試したこと
react-tap-event-plugin
は2.0.1
ではコンパイルできないので3.0.3
にバージョンをあげました
###補足情報
参考サイトの記事は2017/06/12
のものです
###該当のソースコード
jsx
1import React from 'react' 2import ReactDOM from 'react-dom' 3import PropTypes from 'prop-types' 4import {Card, CardActions, CardHeader, CardText} from 'material-ui/Card' 5import FlatButton from 'material-ui/FlatButton' 6import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme' 7import getMuiTheme from 'material-ui/styles/getMuiTheme' 8import injectTapEventPlugin from 'react-tap-event-plugin' 9injectTapEventPlugin() 10 11class CardExampleExpandable extends React.Component{ 12 constructor(props){ 13 super(props) 14 } 15 16 getChildContext(){ 17 return {muiTheme: getMuiTheme(baseTheme)} 18 } 19 20 render(){ 21 return( 22 // カードコンポーネントのDOM 23 <Card> 24 {/* ヘッダー */} 25 <CardHeader 26 title="Rails 5.1サンプルアプリ開発" 27 subtitle="Rails 5.1を体感する為のサンプルアプリケーションを開発する。" 28 actAsExpander={true} 29 showExpandableButton={true} 30 /> 31 {/* アクション */} 32 <CardActions> 33 <FlatButton label="完了" /> 34 <FlatButton label="中止"/> 35 </CardActions> 36 {/* テキスト */} 37 <CardText expandable={true}> 38 ・aaa 39 ・bbb 40 </CardText> 41 </Card> 42 ) 43 } 44} 45 46CardExampleExpandable.childContextTypes = { 47 muiTheme: PropTypes.object.isRequired 48} 49 50document.addEventListener('DOMContentLoaded', () =>{ 51 ReactDOM.render( 52 <CardExampleExpandable />, 53 document.body.appendChild(document.createElement('div')), 54 ) 55}) 56

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。