S
S
Sergey Zolotarev2021-09-29 14:24:55
typescript
Sergey Zolotarev, 2021-09-29 14:24:55

How to fix props reading error in React Navigation?

Good afternoon!
Recently I came across this:


TypeError: Cannot read properties of undefined (reading 'jumpTo')

onPress
/home/head/Desktop/Serge Jr./ITProjects/wccnavigator/pages/stores.tsx:17
14 |
15 | Categories
16 | {
> 17 | return this.props.navigation.jumpTo('CurrentCategory',{cat: item.ID})}>{item.Category}
| ^ 18 | }} />
19 |
20 |

Sample code where clicking on a snippet caused this issue:
import React, {Component} from 'react';
import { FlatList, Text, View } from 'react-native';
import { BottomTabNavigator, NavigationScreenProp } from 'react-navigation';
import { StoresFeed } from '../handlers/stores/homepage/Feed';
import { StoreListService } from '../services/stores/homepage/List';

export interface StoresProps {
      navigation: NavigationScreenProp<any,any>
}
export class Stores extends Component<StoresProps, object>{
  render(){
    return (
      <React.Fragment>
        <View style={screenStyle.list}>
          <Text style={pageStyle.feedList}>Категории</Text>
          <FlatList data={catList} renderItem={({item} : {item: any}) => {
            return <Text style={pageStyle.LCList} onPress={() => this.props.navigation.jumpTo('CurrentCategory',{cat: item.ID})}>{item.Category}</Text>
          }} />
        </View>
      </React.Fragment>
    );
  }
}

const pageStyle = new StoresFeed('ui-change',0).eventStart(),
      screenStyle = new StoresFeed('ui-change',1).eventStart();

const catList = new StoreListService('categories', null).eventStart();

My entire TypeScript project uses React Navigation with an anchored navigator at the bottom of the template. The question itself touched not only this component, but the rest of the problematic code itself in the comments to this question. How to correctly apply props in all React Native components using the same TypeScript?
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question