I need fetch the data from an API and display in an list.There is no error while i run the code. But the data are also not been displayed.
import React, { Component } from 'react';
import {Container, List,Text, StyleProvider} from 'native-base';
import getTheme from './native-base-theme/components';
import material from './native-base-theme/variables/material';
export default class App extends Component {
state = {
data: []
};
componentDidMount() {
this.fetchData();
}
fetchData = async () => {
const response = await fetch("https://randomuser.me/api?results=10");
const json = await response.json();
this.setState({ data: json.results });
};
render() {
console.log(this.state.data);
return (
<StyleProvider style={getTheme(material)}>
<Container>
<List
data={this.state.data}
keyExtractor={(x, i) => i}
renderItem={({ item }) =>
<Text>
{`${item.name.first} ${item.name.last}`}
</Text>}
/>
</Container>
</StyleProvider>
);}}
The list without the api data is working fine