I am trying to get some data from API of eventbrite.
The data is event's name, and the name will be inserted into the list.
In render, buttons are created as many as the number of name which I got from API
I have got few questions below..
How to add information from API into array list - so I can use index, and value.
How to create buttons in forloop
e.g.
for ( var i =0; i<5; i++){
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"/>
} // % buttons are created.
This is my code.
export const renderButtons1 = (numOfBtns,title,site,navigated) => {
const views1 = [];
for ( var i = 0; i < numOfBtns; i++) {
views1.push(
<Button
onPress={(i) => navigate('EventsList', {
Title: title[i]
})
}
title = {title[i]}
color="#841584"
/>);
}
componentDidMount(){
return fetch('https://www.eventbriteapi.com/v3/events/search/location.address=glasgow&token=F7AWKEHKD6BW2TZKWO7N&expand=venue')
.then((response) => response.json())
.then((responseJson) => {
for(var x in responseJson.events){
this.setState({
state : this.state[Events].push(responseJson.events[x][0][0]["text"],"\n",)
});
}})
.catch((error) => {
console.error(error);
});
}
render() {
need to make buttons as many as the number of gotten name from API
}
Array.prototype.map](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…).collection.map(b => <Button ... />)