React Native foreach loop
You can use map or for-of or any other
Example:
// for of
for (let userObject of this.state.users) {
console.log(userObject.username);
}
// map
this.state.users.map((userData) => {
console.log(userData.username);
});
as per the error you may not have data within users
state, so you are getting error. If data is proper then above example will work properly
In react, preferred way is map
method of Array. Example using ES6 arrow function:
render() {
return (
<View>
{dataList.map(r => <Button>{r}</Button>)}
</View>
)
}