Sha256: a8a12240603210253f843f8b22b1f5a6a29efb241b90dd681af6c51ee4e88def
Contents?: true
Size: 1 KB
Versions: 31
Compression:
Stored size: 1 KB
Contents
import React, { PropTypes } from 'react'; import HelloWorldWidget from '../components/HelloWorldWidget'; import _ from 'lodash'; // Simple example of a React "smart" component export default class HelloWorld extends React.Component { static propTypes = { name: PropTypes.string.isRequired, // this is passed from the Rails view }; constructor(props, context) { super(props, context); // 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 }; // Uses lodash to bind all methods to the context of the object instance, otherwise // the methods defined here would not refer to the component's class, not the component // instance itself. _.bindAll(this, 'updateName'); } updateName(name) { this.setState({ name }); } render() { return ( <div> <HelloWorldWidget name={this.state.name} updateName={this.updateName} /> </div> ); } }
Version data entries
31 entries across 31 versions & 1 rubygems