/
HelloWorld.jsx.tt
45 lines (40 loc) · 1.04 KB
/
HelloWorld.jsx.tt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { PropTypes } from 'react';
export default class <%= config[:class_name] %> extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};
/**
* @param props - Comes from your rails view.
* @param _railsContext - Comes from React on Rails
*/
constructor(props, _railsContext) {
super(props);
// How to set initial state in ES6 class syntax
// https://facebook.github.io/react/docs/reusable-components.html#es6-classes
this.state = { name: this.props.name };
}
updateName = (name) => {
this.setState({ name });
};
render() {
return (
<div>
<h3>
Hello, {this.state.name}!
</h3>
<hr />
<form >
<label htmlFor="name">
Say hello to:
</label>
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</form>
</div>
);
}
}