1

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

1 Answer 1

1

change

this.navigation.navigate..

to

this.props.navigation.navigate.
Sign up to request clarification or add additional context in comments.

2 Comments

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..')
got it, i had a bad syntax in edit_note.js, thats why wasnt working, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.