Sha256: f985e88f2ff44bdfe141c56ef8d158e5b9bde664c150bf368776f5c00dbaf054
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
import PropTypes from 'prop-types'; import React from 'react'; export default class HelloWorld extends React.Component { static propTypes = { name: PropTypes.string.isRequired, // this is passed from the Rails view }; /** * @param props - Comes from your rails view. */ constructor(props) { super(props); // How to set initial state in ES6 class syntax // https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class 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: <input id="name" type="text" value={this.state.name} onChange={(e) => this.updateName(e.target.value)} /> </label> </form> </div> ); } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
react_on_rails-12.0.0.pre.beta.0 | lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx |