Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quicksnap/d23d9fb8640bd20db15a4e547fde5bba to your computer and use it in GitHub Desktop.
Save quicksnap/d23d9fb8640bd20db15a4e547fde5bba to your computer and use it in GitHub Desktop.
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 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