Coder Social home page Coder Social logo

I am trying to use react navigation with react-native-super-grid getting error Cannot read property 'navigate' of undefined about react-native-super-grid HOT 3 CLOSED

kobidkunda avatar kobidkunda commented on August 14, 2024
I am trying to use react navigation with react-native-super-grid getting error Cannot read property 'navigate' of undefined

from react-native-super-grid.

Comments (3)

saleel avatar saleel commented on August 14, 2024 2

Its navigation prop is there, it should work.
Anyway, this issue is not associated with the Super Grid. Please try stack overflow with full code and error messages.

from react-native-super-grid.

saleel avatar saleel commented on August 14, 2024

Probably because this.props.navigation is undefined. Are you sure this navigation prop is passed from the parent component?

from react-native-super-grid.

kobidkunda avatar kobidkunda commented on August 14, 2024

props is there . This is working code

`import React, {Component} from 'react';
import {
StyleSheet,
Text, StatusBar,TouchableOpacity,
View, Image, Dimensions,ScrollView,ActivityIndicator,TouchableHighlight
} from 'react-native';
import GridView from 'react-native-super-grid';
let BASE_URL = 'https://abc.xyz';
let PRODUCT_URL = '/api/products/all';
import { withNavigation } from 'react-navigation';

const {width, height} = Dimensions.get('window');

class Product extends Component<{}> {

constructor(props) {
    super(props);

    this.goToProductDetails = this.goToProductDetails.bind(this);

    this.state = {
        products : [],
        ProductsLoaded:false,
    };
   
}



goToProductDetails = async (item) => {

console.log(item)

    this.props.navigation.navigate('ProductDetails',{
        ProductName: item.name,
        ProductSlug: item.slug,
    })
  //  this.props.navigation.navigate('ProductDetails');


}




async  componentDidMount(){

    let response = await fetch(BASE_URL + PRODUCT_URL, {
        method: 'GET',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
    });

    let data = await response.json();
    let products = data.product.data;
    this.setState({ products: products});
    this.setState({ ProductsLoaded: true});
}

render() {

    let items = this.state.products;




   if (this.state.ProductsLoaded === true){
       return  (

           <View style={styles.productContainer}>
               <Text style={styles.productContainerTitle}>Best Selling Mobiles</Text>
               <GridView
                   itemDimension={140}
                   items={items}
                   style={styles.gridView}



                   renderItem={item => (
                       <TouchableOpacity style={[styles.itemContainer, { backgroundColor: '#ffffff' }]}
                                        // onPress={this.goToProductDetails}
                                         onPress={() => this.goToProductDetails(item)}



                       >
                           <Image
                               style={styles.ProductImage}
                               source={{uri: item.product_primary_images.cdn_url }}
                           >

                           </Image>
                           <Text style={styles.itemName}>{item.name.slice(0,15)}</Text>
                           <Text style={styles.itemPrice}>
                               ₹ {item.listing_price}</Text>
                       </TouchableOpacity>
                   )}
               />
           </View>

       )
   } else
    return (

           <View style={styles.productContainer}>
               <Text style={styles.productContainerTitle}>Best Selling Mobiles</Text>

               <View style={styles.gridViewLoading}>

                   <ActivityIndicator size="large" color="#4b8ccd" />

               </View>


           </View>

    );
}

}`

from react-native-super-grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.