Sha256: ded1f02e966fab8511069496c0366e6ba721c91aecbec956716f6605ac02a9ef
Contents?: true
Size: 1006 Bytes
Versions: 31
Compression:
Stored size: 1006 Bytes
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: </label> <input id="name" type="text" value={this.state.name} onChange={(e) => this.updateName(e.target.value)} /> </form> </div> ); } }
Version data entries
31 entries across 31 versions & 1 rubygems