LoginSignup
4
3

More than 3 years have passed since last update.

[Rails]Reactをインストールする (RailsでReactを利用する)

Last updated at Posted at 2021-04-21

最初に

自分のRailsアプリでReactを使ったのでインストール方法を備忘録として残しておきます。

手順

Gemfile
gem 'react-rails'
$ bundle install
$ rails webpacker:install:react
$ rails g react:install

以上でRailsにReactを実装できます。

コンポーネントの作成

コンポーネントとはなんぞやという方は以下の記事をお読みください

$ rails g react:component hoge  ← 作りたいコンポーネントの名前

すると
app/javascript/components下にhoge.jsが作成されます

そしてhoge.jsを名前変更しhoge.jsxに変更します。
するとReact専用のファイルとして利用することができます

4
3
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
4
3