Guest User

Untitled

a guest
Dec 16th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import './ListCard.css';
  2. import Card from './Card';
  3.  
  4. const ListCard = (props) =>{
  5. //Esto lo muestra correctamente
  6. console.log(props.properties)
  7. //Aquí me da 0, y por ende, no me muestra los valores en props.properties.map
  8. console.log(props.properties.length)
  9. return(
  10. <div className='ListCard'>
  11. {
  12. props.properties.map((property)=>{
  13. return <Card key={property.id}
  14. id={property.id}
  15. primaryTitle={property.primaryTitle}
  16. subtitle={property.subtitle}
  17. supportingText={property.supportingText}
  18. onClick={property.onClick}
  19. actions={props.actions}
  20. src={property.image} />
  21. })
  22. }
  23. </div>
  24. )
  25. }
  26.  
  27. ListCard.propTypes = {
  28. properties: PropTypes.array.isRequired
  29. }
  30.  
  31. export default ListCard;
  32.  
  33. class Products extends React.Component{
  34. constructor(props){
  35. super(props);
  36. this.state={
  37. actions: [],
  38. error: false,
  39. queryResult: [],
  40. spinner: true
  41. }
  42. }
  43. componentDidMount(){
  44. let actionsValues = [
  45. {
  46. id: 'btnAdd',
  47. text: 'Añadir',
  48. onClick: ()=> {
  49. //Add the product to the cart
  50. console.log('Hay que implementarlo');
  51. }
  52. }
  53. ];
  54.  
  55. const codeQuery = allProducts().code;
  56.  
  57. this.setState(update(this.state, {
  58. actions: {$set: actionsValues},
  59. error: {$set: (codeQuery === -1) ? true : false},
  60. queryResult: {$set: (codeQuery !== -1) ? allProducts().result : allProducts().errorMessage},
  61. spinner: {$set: (codeQuery !== -1) ? false : true}
  62. }));
  63. }
  64. render(){
  65. const list = (this.state.spinner)
  66. ? <Spinner />
  67. : <ListCard properties={this.state.queryResult} actions={this.state.actions} />;
  68. return (
  69. <div className='Products'>
  70. {list}
  71. </div>
  72. )
  73. }
  74. }
Add Comment
Please, Sign In to add comment