- Alpha preview: Using React with importmaps on Rails 7 - no JSX
- Alpha preview: Converting a import-mapped React app to use esbuild with JSX in Rails 7 - no import maps
What if you could have JSX and import maps?
What follows ia a proof of concept of exactly that!
-
rails new reakt --dev
-
cd react
-
copy importmap-jsx.rb (above) to
config/initializers
-
./bin/rails generate controller components index
-
add to app/views/components/index.html.erb:
<div id="root"></div>
-
change
get
in config/routes.rb to:root 'components#index'
-
./bin/importmap pin react react-dom
-
add to config/importmap.rb:
pin_all_from "app/javascript/components", under: "components"
-
mkdir app/javascript/components
-
add to app/javascript/application.js:
import "components"
-
add to app/assets/config/manifest.js:
//= link_tree ../../javascript/components .jsx
-
create app/javascript/components/index.jsx:
import React from "react" import { render } from "react-dom" render( <h1>hello world</h1>, document.getElementById("root") )
-
./bin/rails server
-
visit http://localhost:3000/
What license is this released under?