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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -