Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Navigating to the homeScreen after setting up the user's profile

I've figured out how to navigate from the signupScreen to homeScreen using React-navigation along with firebase-authentication but I've added an additional screen. This is the profileSetupScreen. My issue is that I can't navigate from the set-up screen to homeScreen after getting the data from the user. The finish button is suppposed to 'addData' then navigate to homeScreen but I can't figure that out.

Please ask if you need more info. Here is a portion of my code. What should I add?

//...
//This adds the users data onto firebase
const addData = () => {
    try {
      const docRef = addDoc(collection(db, "users"), {
        nickname,
        bio,
        selectedImage,
        dbEmail,
      });
      console.log("Document written with ID:", docRef.id);
    } catch (e) {
      console.error("Error adding document: ", e);
    }
  };

  //Overall UI
  return (
//Once 'Finish' is pressed, it saves the data onto FireStore and should navigate to homeScreen
    <View style={styles.all}>
      <Text style={styles.title}>Profile Setup</Text>
      <View style={styles.selectionView}>
        <TouchableOpacity style={styles.completebtn} onPress={onSignOut}>
          <Text style={styles.backtxt}>Back</Text>
        </TouchableOpacity>
        <TouchableOpacity style={styles.completebtn} onPress={addData}>
          <Text style={styles.completetxt}>Finish</Text>
        </TouchableOpacity>
      </View>
//...
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It depends on whether or not ProfileSetupScreen is a Screen defined in the navigator. If it is, then the navigation framework will pass the navigation prop to the ProfileSetupScreen and you can use it as follows via the screen props.

const ProfileSetupScreen = ({navigation}) => {

  const addData = () => {
    try {
      const docRef = addDoc(collection(db, "users"), {
        nickname,
        bio,
        selectedImage,
        dbEmail,
      });
      console.log("Document written with ID:", docRef.id);
    navigation.navigate(”HomeScreen”)
    } catch (e) {
      console.error("Error adding document: ", e);
    }
  };

  return (…)
}

Notice, that navigation.navigate(”HomeScreen“) take the name of the screen to which we want to navigate and which is defined in the navigator, thus if your Home Screen is defined there with a different name, then you need to use that name.

If your ProfileSetupScreen is not a screen in your navigator, then the navigation prop will not be passed to the screen.

In this case you have two choices. Either pass the navigation prop down to the component from a parent screen that is a defined screen in the navigator or use the useNavigation hook as follows.


const ProfileSetupScreen = (props) => {
   const navigation = useNavigation()
…

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!