-2
I’m trying to show a box with a result of an Axios request using Flatlist but the screen is just blank, no error or anything.
export default class Home extends Component {
state = {
posts: [],
};
componentDidMount = ()=>{
this.getPostagem();
};
getPostagem= async ()=>{
const id = await AsyncStorage.getItem('id');
await api.get("postagens").then( res => {
this.setState({ posts: res.data.posts });
});
};
renderItem = ({ item }) => (
<View style={styles.listItem}>
<Text>{item.criador}</Text>
</View>
);
render() {
return (
<FlatList
style={{ marginTop: 30 }}
contentContainerStyle={styles.list}
data={this.state.posts}
renderItem={this.renderItem}
//keyExtractor={item => item.texto}
/>
);
}
}