Im pretty nub at react and JS, so, this is probably a stupid question, but, when I try to use the .map() in a array like this:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
export default class App extends React.Component {
productsArray = [
'Cajo T-shirt',
'Geometric Skull',
'Bavaria 350 mL',
'Inflatable Alien',
'R2D2 RC Car',
];
renderCategories(arrayDeProdutos) {
return arrayDeProdutos.map((index) => <Text key={index}></Text>);
}
render() {
return (
<View style={styles.container}>
{this.renderCategories()}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
I got the following error message: "arrayDeProdutos.map is not a object". I tryed to read the map documentation, but it did'n answered my question.
{this.renderCategories(this.productsArray)}{this.renderCategories()}you need to pass argument. Change to{this.renderCategories(this.productsArray)}