Wednesday, 19 April 2017

Rendering data from database

I am using react native to build an application. Using node js , express and mysql for the backend. Inserting data seems to work fine. But i am not able to retrieve data from the tables. This is the fetch API that i tried but i am not sure it is correct. I am new to React Native.

export default class UserProfile extends Component{
constructor(props) {
                        super(props);
                          this.state = {
                                   name:'',
                                   email:'',
                                          }
                    };
componentWillMount(){
                  return this.getUser;
                  }
  getUser(){
  return fetch('http://192.168.0.20:3000/userprofile',{
  method:'POST',
  headers:{
          'Accept':'application/json',
          'Content-Type':'application/json',
          }
         })
  .then((response) => response.json())
  .then((responseData) => {responseData})
         }
render(){
  return(
    <Text>Name : this.state.name</Text>
   );
 }
}



via Avikrit Khati

No comments:

Post a Comment