Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Created September 11, 2015 09:54
Show Gist options
  • Select an option

  • Save nsisodiya/9d6ee3b7867a51341115 to your computer and use it in GitHub Desktop.

Select an option

Save nsisodiya/9d6ee3b7867a51341115 to your computer and use it in GitHub Desktop.
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;
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