[reactjs] Having services in React application

I also came from Angular.js area and the services and factories in React.js are more simple.

You can use plain functions or classes, callback style and event Mobx like me :)

_x000D_
_x000D_
// Here we have Service class > dont forget that in JS class is Function_x000D_
class HttpService {_x000D_
  constructor() {_x000D_
    this.data = "Hello data from HttpService";_x000D_
    this.getData = this.getData.bind(this);_x000D_
  }_x000D_
_x000D_
  getData() {_x000D_
    return this.data;_x000D_
  }_x000D_
}_x000D_
_x000D_
_x000D_
// Making Instance of class > it's object now_x000D_
const http = new HttpService();_x000D_
_x000D_
_x000D_
// Here is React Class extended By React_x000D_
class ReactApp extends React.Component {_x000D_
  state = {_x000D_
    data: ""_x000D_
  };_x000D_
_x000D_
  componentDidMount() {_x000D_
    const data = http.getData();_x000D_
_x000D_
    this.setState({_x000D_
      data: data_x000D_
    });_x000D_
  }_x000D_
_x000D_
  render() {_x000D_
    return <div>{this.state.data}</div>;_x000D_
  }_x000D_
}_x000D_
_x000D_
ReactDOM.render(<ReactApp />, document.getElementById("root"));
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>_x000D_
<!DOCTYPE html>_x000D_
<html>_x000D_
<head>_x000D_
  <meta charset="utf-8">_x000D_
  <meta name="viewport" content="width=device-width">_x000D_
  <title>JS Bin</title>_x000D_
</head>_x000D_
<body>_x000D_
  _x000D_
  <div id="root"></div>_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>_x000D_
_x000D_
</body>_x000D_
</html>
_x000D_
_x000D_
_x000D_

Here is simple example :