Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Created Jun 27, 2018
Embed
What would you like to do?
Using observables in react app
import * as React from "react";
import { httpGet } from "./service";
import "./App.css";
import logo from "./logo.svg";
class App extends React.Component {
constructor({}) {
super({}, null);
httpGet("http://abc.com/api/location/country").subscribe({
next: data => {
console.log("deded");
},
error: err => {
console.log("deddd");
}
});
}
public render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.tsx</code> and save to reload.
</p>
</div>
);
}
}
export default App;
import axios from "axios";
import { from } from "rxjs";
export function httpGet(url) {
return from(axios.get(url));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment