Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class Category extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isLoading: false,
- categories: [],
- loaded:false,
- page: 1,
- };
- }
- static navigationOptions = {
- headerTitle: 'Categories',
- title: 'Categories',
- };
- componentDidMount() {
- this.fetchCategories();
- }
- fetchCategories() {
- this.setState({isLoading: true});
- categoryApi.getAll(this.state.page).then(response => {
- if (response.data) {
- console.log(response.data);
- this.setState({
- categories: this.state.categories.concat(response.data),
- isLoading: false,
- });
- } else {
- this.setState({isLoading: false});
- console.log(response);
- Alert.alert(
- constants.app.errorTitle,
- constants.app.errorMessage,
- [],
- {cancelable: true}
- )
- }
- });
- }
- componentWillMount() {
- }
- render() {
- const {navigate} = this.props.navigation;
- return (
- <View style={styles.container}>
- <View style={styles.projektiHeader}>
- <Text style={styles.projekti}>VALITSE PROJEKTI</Text>
- </View>
- <View style={styles.categoriesList}>
- <FlatList
- data={this.state.categories}
- extraData={this.state}
- renderItem={(rowData) => <CategoryItem navigate={navigate} item={rowData}/>}
- onEndReached={this.showMore}
- keyExtractor={(item, index) => index}
- // onEndReachedThreshold={0.5}
- />
- </View>
- <View style={styles.shopsNear}>
- <ShopsNear navigate={navigate}/>
- </View>
- </View>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement