Created
June 27, 2018 10:09
-
-
Save jyotendra/41b008c75e915d9bf6213267322a82d8 to your computer and use it in GitHub Desktop.
Using observables in react app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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