Add React and TS to webpacker; add react-rails gem

This commit is contained in:
riggraz
2019-08-25 14:34:20 +02:00
parent 01cc6eb96a
commit 24339c0e08
14 changed files with 304 additions and 7 deletions

View File

View File

@@ -0,0 +1,19 @@
import * as React from "react";
interface IProps {
name: string;
}
class Hello extends React.Component<IProps> {
render () {
const {name} = this.props;
return (
<React.Fragment>
<span>Hello {name}!</span>
</React.Fragment>
);
}
}
export default Hello;

View File

@@ -17,3 +17,7 @@ require("../stylesheets/application")
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
// Support component names relative to this directory:
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

View File

@@ -0,0 +1,5 @@
// By default, this pack is loaded for server-side rendering.
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

View File

@@ -1,2 +1,6 @@
<h1><%= @board.name %></h1>
<p><%= @board.description %></p>
<%=
react_component('Hello', { name: 'TypeScript on React on Rails' })
%>