0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RailsにReact Railsを導入する

Posted at

手順をメモ書きしておきます。

Gemfileに下記の記述を追加

gem 'react-rails'

ReactRailsの初期化

rails g react:install

React コンポーネントの作成

react-rails には、React Component 定義を生成してくれる generator があるため、
それを使用して Component を作成します。

rails g react:component 任意のコンポーネント名

コンポーネント作成時、任意のコンポーネント名の後に「Props」と「Propsの型」を指定することもできます。

rails g react:component StoreInfo storeName:string

コマンドを実行すると
app/javascript/components直下にコンポーネントが作成されます。

上記のコマンドで作成されたコンポーネント

StoreInfo.jsx
import React from "react"
import PropTypes from "prop-types"
class StoreInfo extends React.Component {
  render () {
    return (
      <React.Fragment>
        Store Name: {this.props.storeName}
      </React.Fragment>
    );
  }
}

StoreInfo.propTypes = {
  storeName: PropTypes.string
};
export default StoreInfo
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?