Created
April 18, 2018 19:04
-
-
Save pixelknitter/1eeee3db3a13616ec499052f50dd7822 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component } from 'react'; | |
import { Text, View } from 'react-native'; | |
import axios from 'axios'; | |
import Product from '../../models/Product' | |
// Note the special import here! | |
interface ICardCollectionProps { | |
} | |
interface ICardCollectionState { | |
products: any[] | |
} | |
class CardCollection extends Component<ICardCollectionProps, ICardCollectionState> { | |
constructor(props: ICardCollectionProps) { | |
super(props); | |
this.setState({ | |
products: [] | |
}); | |
} | |
componentWillMount() { | |
axios.get('http://localhost:3001/products') | |
.then((response) => this.setState({ products: response.data })) | |
} | |
renderProducts() { | |
if (this.state.products !== null) { return; } | |
this.state.products.map((product) => | |
<Text key={product.productCode}>{product.productCode}</Text> | |
); | |
} | |
render() { | |
console.log(this.state) | |
return ( | |
<View> | |
{this.renderProducts()} | |
</View> | |
); | |
} | |
} | |
export default CardCollection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment