Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] javascript – How can I use navigation in a class component? REACT-NATIVE

Posted on November 14, 2022

Solution 1 :

change

this.navigation.navigate..

to

this.props.navigation.navigate.

Problem :

im new in react-native and I want to know how can i use the prop navigation in my class component, because it doesnt has it, let me show my code:

heres the home screen where I call my class component Notes:

render() {
    return (
        <>
        <View style = {this.styles.container}>
            <View>
                <Text style = {this.styles.Text}>Welcome to home!</Text>
            </View>
            <Notes data = {this.state.array_notes} navigation = {this.props.navigation}></Notes>        
            <View style = {this.styles.View}>                                                                                                 
                <Button title = "Create new note" onPress = {() => this.props.navigation.navigate("Create_note", {fetch_notes: this.fetch_notes.bind(this)})}></Button>
            </View>                                                                                                                           
            <View style = {this.styles.View2}>
                <Button title = "Notes" styles = {this.styles.Button} onPress = {() =>this.props.navigation.navigate("See_notes")}></Button>
            </View>
        </View>
        </>
    );

as you can see, im passing to it two props, data and navigation, in my class component Notes and use them like this:

render() {
    return (
        <>
        <View style = {this.styles.View}>
           <FlatList data = {this.props.data} renderItem = {({item}) => (<TouchableOpacity onPress = {this.navigation.navigate("Edit_note")}><Text style = {this.styles.Text}>{item.title}</Text></TouchableOpacity>)} keyExtractor = {(item) => item.note_number.toString()}></FlatList>
        </View>
        </>
    );
}

with the prop data it works, but with navigation it shows me this error:

enter image description here

what im doing wrong? i dont any variable call params.data

Comments

Comment posted by D10S

I didn’t read your question to the end of it. The error you are getting might be caused since you forgot to write “props” (‘this.navigation.navigate..’ ==> ‘this.props.navigation.navigate..’)

Comment posted by plus

got it, i had a bad syntax in edit_note.js, thats why wasnt working, thanks 🙂

READ  [ANSWERED] Upload file into azure storage using sas url in android using Java
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress