2017-05-26 2 views

答えて

32

まずインストールmaterial-ui

npm install --save material-ui react-tap-event-plugin 

または

yarn add material-ui react-tap-event-plugin 

これらはあなたがCRA

src/index.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 

import injectTapEventPlugin from 'react-tap-event-plugin'; // add 

import './index.css'; 
import App from './App'; 
import registerServiceWorker from './registerServiceWorker'; 

injectTapEventPlugin(); // add 

ReactDOM.render(<App />, document.getElementById('root')); 
registerServiceWorker(); 
material-ui仕事をするために変更する必要がありますファイルです要約すると0

src/App.js

import React, { Component } from 'react'; 

import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; // add 
import RaisedButton from 'material-ui/RaisedButton'; // add 

import logo from './logo.svg'; 
import './App.css'; 

class App extends Component { 
    render() { 
    return (

     <MuiThemeProvider> 

     <div className="App"> 
     <div className="App-header"> 
      <img src={logo} className="App-logo" alt="logo" /> 
      <h2>Welcome to React</h2> 
     </div> 
     <p className="App-intro"> 
      To get started, edit <code>src/App.js</code> and save to reload. 
     </p> 

     <RaisedButton label="Material UI" /> 

     </div> 

     </MuiThemeProvider> 

    ); 
    } 
} 

export default App; 

、これらが行うべきものです:

  • 必要なパッケージをインストールします。
  • インポートinjectTapEventPluginreact-tap-event-pluginindex.jsからそれを初期化します。 iOSのタップ遅延を削除するには の中でinjectTapEventPluginが使用されます。 App.js
  • 輸入MuiThemeProviderコンポーネント、私はインストールの最初のステップのためにここに
+0

ありがとうございます。 1つずつコンポーネントをインポートせずにすべてのコンポーネントを使用できる方法はありますか? – FewFlyBy

+1

これは、始めている人からはかなり頻繁に聞かれる質問です。基本的にJSのモジュール・パラダイムは、分離された再利用可能なコンポーネントに根ざしています。彼らは一度にすべてを輸入できるより大きな生態系の一部ではありません。これはかなり大きな話題ですが、要するに、すべてのMaterial-UIを1つのステートメントでインポートすることはできません。 –

+0

'react-tap-event-plugin'の理由は、iOSブラウザの問題の回避策と同じであり、問​​題には必須ではありません。 – WorldSEnder

0

RaisedButtonを使用ようにあなたがmaterial-uiで任意のコンポーネントをインポートして使用することができます今、私がする必要MuiThemeProviderコンポーネント

  • でアプリのdiv要素を囲みこれを動作させるには: npm install --save material-ui axios react-tap-event-plugin

  • +0

    なぜaxios? axiosは約束のライブラリです。材料とは何の関係もない –

    関連する問題