ios - Printing arrays to screen in React Native -


i want print couple of arrays on screen in react native ios app. right nothing showing on screen. console.logs after loop show arrays have data supposed have, not reflected on screen. how render again after fetch call has loaded? here's code:

'use unique' import react, { component } 'react'; import {   stylesheet,   touchablehighlight,   text,   view,   listview } 'react-native';  import api './apicall';  class apirequest extends component {    constructor() {     super();      this.state = {       users: [],       id: [],       type: []     }   }    componentwillmount() {        api.getdata()         .then((res) => {           this.setstate({             users: res           })           (var = 0; < this.state.users.length; i++) {             this.state.id.push(this.state.users[i].id);             this.state.type.push(this.state.users[i].type);       });   }    render() {     return(       <view style={styles.container}>         <text style={styles.buttontext}>           {this.state.id}         </text>       </view>     );   } } 

this.state.id.push(this.state.users[i].id); this.state.type.push(this.state.users[i].type); 

that's wrong way set new state. should following:

var idarray = []; var typearray = []; (var = 0; < this.state.users.length; i++) {   idarray.push(this.state.users[i].id);   typearray.push(this.state.users[i].type); } this.setstate({id: idarray}); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

c# - Json.Net Serialize String from URI -

ruby on rails - What is the best design practise to create tables from same controller using same actions -