简体   繁体   中英

how to display data from api by id in react native

I have this simple react native demo and i want to display data by specific id no all the data how can i do this ??

      componentDidMount(){
    return fetch('http://209.97.188.74/api/scategories')
      .then((response) => response.json())
      .then((responseJson) => {
        this.setState({
          isLoading: false,
          dataSource: responseJson.data,
        }, function(){
            });
          })
         }
      render(){
          return(
      <View>
        <FlatList
          data={this.state.dataSource}
          renderItem={({item}) => <Text>{item.id}, {item.name}</Text>}
          keyExtractor={({id}, index) => id}
        />
      </View>
    );
  }

Try putting your fetch() inside of a setTimeout()

Like this:

 setTimeout(() => { fetch('http://209.97.188.74/api/scategories') .then((response) => response.json()) .then((responseJson) => { this.setState({ isLoading: false, dataSource: responseJson.data, }); }); }, 100); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM