Created
June 4, 2020 13:02
-
-
Save JoshK2/8212d62836d3ced189fda293593a2338 to your computer and use it in GitHub Desktop.
Store - products list component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {StyleSheet, View} from 'react-native'; | |
import PropTypes from 'prop-types'; | |
import {Product} from './product'; | |
const styles = StyleSheet.create({ | |
container: {flex: 1, alignItems: 'center', justifyContent: 'flex-start'}, | |
}); | |
const ProductsList = ({list}) => { | |
return ( | |
<View style={styles.container}> | |
{list.map((product, index) => ( | |
<Product | |
key={index} | |
title={product.title} | |
description={product.description} | |
price={product.price} | |
image={product.image} | |
addToCart={product.stock > 0} | |
/> | |
))} | |
</View> | |
); | |
}; | |
ProductsList.propTypes = { | |
list: PropTypes.arrayOf( | |
PropTypes.shape({ | |
title: PropTypes.string, | |
description: PropTypes.string, | |
price: PropTypes.string, | |
image: PropTypes.string, | |
stock: PropTypes.number, | |
}), | |
), | |
}; | |
export {ProductsList}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment