Created
September 11, 2015 09:54
-
-
Save nsisodiya/9d6ee3b7867a51341115 to your computer and use it in GitHub Desktop.
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 React, {Component} from 'react'; | |
| import request from 'superagent-bluebird-promise'; | |
| class AjaxGet extends Component { | |
| constructor(props, context) { | |
| super(props, context); | |
| this.state = { | |
| data: {} | |
| }; | |
| var component = this; | |
| request.get(this.props.url).then(function (res) { | |
| component.setState({ | |
| data: res.body | |
| }) | |
| }); | |
| } | |
| render() { | |
| const child = this.props.children; | |
| const newChild = React.cloneElement( | |
| child, | |
| {json: this.state.data} | |
| ); | |
| return <div>{newChild}</div> | |
| } | |
| } | |
| AjaxGet.defaultProps = {}; | |
| export default AjaxGet; |
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 React, {Component} from 'react'; | |
| import AjaxGet from './AjaxGet.js'; | |
| import JSONViewer from 'react-json-viewer' | |
| class DemoAjax extends Component { | |
| constructor(props, context) { | |
| super(props, context); | |
| } | |
| render() { | |
| return ( | |
| <AjaxGet url='http://localhost:3000/api/properties'> | |
| <JSONViewer json={{}}/> | |
| </AjaxGet> | |
| ); | |
| } | |
| } | |
| DemoAjax.defaultProps = {}; | |
| export default DemoAjax; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment