react-sails

0.1.2 • Public • Published

react-sails

Integrate sails model into React UI.

Example Usage

class Application extends React.Component {
  render() {
    return (
      <SailsApp initialData={window.data}>
        <div>
          <Table model="Book" />
        </div>
      </SailsApp>
    );
  }
}
 
class Table extends React.Component {
  render() {
    const model = this.context.getSailsModelCache(this.props.model);
    if (!model.isReady()) {
      return <div>Loading...</div>
    } else {
      return (
        <table>
          <thead>
            <tr><th>Column 1</th><th>Column 2</th></tr>
          </thead>
          <tbody>
            {model.forEach(rec => (
              <tr><td>{rec.col1}</td><td>{rec.col2}</td></tr>
            ))}
          </tbody>
        </table>
      );
    }
  }
}
 
Table.contextTypes = {
  // The method provided by SailsApp
  getSailsModelCache: React.PropTypes.func.isRequired
}
export default Table;

Readme

Keywords

none

Package Sidebar

Install

npm i react-sails

Weekly Downloads

0

Version

0.1.2

License

MIT

Last publish

Collaborators

  • syaau