reactjs - Call an API using superagent? -
i have api consists branch of data
{ "data": { "id": , "title": , "description": , "old_price": "100", "new_price": "50", "size": "50", "quantity": 20, }, "errors": null, "code": 1 }
i using superagent in order call api , render information, doing in wrong way.
here code
import react 'react'; import {render} 'react-dom'; import superagent 'superagent'; import layout './components/layout'; class app extends react.component{ constructor(){ super() this.state={ name:'' } } componentdidmount(){ console.log('componentdidmount'); const url='http://...'; superagent .get(url) .query(null) .set('accept', 'application/json') .end ((error, response)=>{ const title=response.body.response console.log(json.stringify(title)); this.setstate({ name:title }) }) } render(){ return( <layout data={this.state}/> ) } } render(<app />, document.getelementbyid('app'));
here render it
import react 'react'; export default class layout extends react.component{ render(){ let data = this.props.data; return ( <div> {data.name} </div> ) } }
but not rendering, think doing in wrong way. please me that.
const title=response.body.response
should be
const title=response.body
most likely
Comments
Post a Comment