0

Hi guys I am having trouble finding a solution on my problem because I want to navigate to another page but here's the problem

function NewOrderPopUp({id, services, name, rating, accepted, destinationPlaceName, userPlaceName, driverName, driverContactNumber, driverRating, driverTrackingNumber})
{
    async function toggleAcceptBooking()
    {
        await firestore()
        .collection('userBookingRequest')
        .doc(id)
        .update({
            accepted : !accepted,
            driverName: 'Sample Driver',
            driverContactNumber: '09123456789',
            driverRating: '4.9',
            driverPlateNumber: 'NFT-2020',
            driverTrackingNumber: GenerateTrackingNumber(),
        })
        CheckIfBookingAccepted();
    }
}

return (
        <View>....</View>
);

export default NewOrderPopUp;

And I am calling the NewOrderPopUp Page in another file. like this

import NewOrderPopUp from "../../components/NewOrderPopUp";
const HomeScreen = () => {

//... codes here

return (
<View>
    <FlatList
         horizontal
         contentContainerStyle={{paddingHorizontal: 30}}
         data={userBookingData}
         keyExtractor={(item) => item.id} 
         renderItem={({item}) => <NewOrderPopUp {...item}/>} />                     
</View>
);
}
export default HomeScreen;

What I wanted is that if I click the toggleAcceptBooking it will nagivate to another page like

navigation.navigate('BookingPage');

Can someone enlighten me please . Thank you.

1
  • 1
    Add nav script in CheckIfBookingAccepted() or after the firestore() promise resolve Commented Aug 16, 2021 at 16:10

1 Answer 1

1

Do it by passing navigation down as a prop.

do the following steps.

  1. handle navigation prop in HomeScreen
const HomeScreen = ({ navigation }) => {

}
  1. pass navigation as a prop to NewOrderPopUp
<FlatList
    ...
    renderItem={({item}) => <NewOrderPopUp navigation={navigation} {...item}/>} />
  1. handle navigation prop in NewOrderPopUp and use it to navigate.
function NewOrderPopUp( {navigation, ...} ){
    async function toggleAcceptBooking(){
        await ...
        navigation.navigate('BookingPage');
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

TypeError: undefined is not an object (evaluating 'navigation.navigate') I am having this error
"@react-navigation/native": "^6.0.2", "@react-navigation/stack": "^6.0.6",
please update your question with the code to can find the error.

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.