Skip to content

11. (NEW) React SDK

Jonathan Casarrubias edited this page Oct 5, 2017 · 1 revision

ReactJS SDK Support

From version 2.1.0-rc.14 the LoopBack SDK Builder now supports React JS. The current implementation is not yet as mature as the Angular 2+ one, but currently provides the following features:

  • Generate SDKs for React Apps
  • Models and Services

Setup

$ ./node_modules/.bin/lb-sdk server/server.js /path/to/client/sdk -l react -i disabled -t false

Just note that for now you need to disable real-time features -i (io module Real Time Communication) and typingsas well -t (Typed SDK) is false, for now io and typings are not available for react.

Use Services in a React Component

Following the High-Order Components (HOC) Pattern, you will require to extend the Component class available in your generated SDK, it will provide to you any service or model but also React functionality.

Finally you can inject the generated services by calling super() as follows:

import React from 'react';
import SDK, { Component } from './shared/sdk/';

class App extends Component {
  constructor() {
    super({services: ['RoomApi']});
  }
  componentDidMount() {
    this.RoomApi.find().subscribe(data => {
      console.log(data);
    })
  }
  render() {...}
}

export default App;

Note

The React SDK is currently under development, more features and documentation will be added in a near future.

Clone this wiki locally