Sha256: a9303a65a4f71e3bced56d79363f5fef2dfd92b8c4c9b0ab49c5345d11dca10e

Contents?: true

Size: 938 Bytes

Versions: 3

Compression:

Stored size: 938 Bytes

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);

    // 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');
  }

  state = {name: this.props.name} // how to set initial state in es2015 class syntax

  _updateName(name) {
    this.setState({name: name});
  }

  render() {
    return (
      <div>
        <HelloWorldWidget name={this.state.name} _updateName={this._updateName} />
      </div>
    );
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
react_on_rails-2.0.0.rc.1 lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx
react_on_rails-2.0.0.beta.3 lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx
react_on_rails-2.0.0.beta.2 lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx