From 2f30448bd9d9ae45480200b76ae60b534eaa14c9 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 3 Oct 2017 15:51:34 +0100 Subject: [PATCH 1/2] JSX file in components folder --- app/javascript/components/User.jsx | 18 ++++++++++++++++++ app/views/welcome/index.html.erb | 1 + 2 files changed, 19 insertions(+) create mode 100644 app/javascript/components/User.jsx diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx new file mode 100644 index 0000000..de95fe0 --- /dev/null +++ b/app/javascript/components/User.jsx @@ -0,0 +1,18 @@ +var React = require("react") +var PropTypes = require("prop-types") +class User extends React.Component { + render () { + return ( +
+
Name: {this.props.name}
+
Age: {this.props.age}
+
+ ); + } +} + +User.propTypes = { + name: PropTypes.String, + age: PropTypes.Integer +}; +module.exports = User diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 4dd0f9d..6eaa474 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,2 +1,3 @@ <%= javascript_pack_tag 'application' %> <%= react_component 'Post', { title: 'A working react component', body: 'Simple but effective' }, prerender: true %> +<%= react_component 'User', { name: 'Timmy', body: 26 }, prerender: true %> From 14903cef8333cefe4c4f60416c77805b07328f37 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 5 Oct 2017 15:10:21 +0100 Subject: [PATCH 2/2] Actually pass an age through --- app/views/welcome/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 6eaa474..0751eb2 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,3 +1,3 @@ <%= javascript_pack_tag 'application' %> <%= react_component 'Post', { title: 'A working react component', body: 'Simple but effective' }, prerender: true %> -<%= react_component 'User', { name: 'Timmy', body: 26 }, prerender: true %> +<%= react_component 'User', { name: 'Timmy', age: 26 }, prerender: true %>