react-sails

Integrate sails.js application model into React UI.

Usage no npm install needed!

<script type="module">
  import reactSails from 'https://cdn.skypack.dev/react-sails';
</script>

README

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;