Sha256: d840eb03f843a95aa43c4fadaf11fb82a7859bd49d5b091c0655be48c78f8ff4
Contents?: true
Size: 1.04 KB
Versions: 17
Compression:
Stored size: 1.04 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. * @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> ); } }
Version data entries
17 entries across 17 versions & 1 rubygems