0

I am trying to navigate to another page after Firebase sign up finishes, so I tried to use useHistory hook to navigate to next page after signing up is successful the signing up was successful but the hook doesn't work, the console doesn't show any errors

and if the hook doesn't work for such case, how can I navigate to next page if sign up was successful?

    import {useHistory} from 'react-router-dom'
const history = useHistory();
      function signup(event) {
        console.log({email, password});
        
        firebase.auth().createUserWithEmailAndPassword(email, password)
          .then((user) => {
            // Signed in 
            // ...
            
            this.history.push('/Quiz')
            console.log(email, password)
            
            firebase.database().ref('users/' + user.uid).set({ email: user.email, password: user.password });
           
          })
          .catch((error) => {
            var errorCode = error.code;
            var errorMessage = error.message;
            // ..
            console.log(errorMessage)
            
          });
          
      }
mai mohamed
  • 105
  • 5
  • 19

1 Answers1

0

you can to this

app.js

import React from "react";
import ReactDOM from "react-dom";
import { createBrowserHistory } from "history";
import Routes from './routes'
const history = createBrowserHistory();

ReactDOM.render(<Router history={history}><Routes/></Router>, node);

signup.js

      import {useHistory} from 'react-router-dom'
      const AppName = () => {
      const history = useHistory();

      function signup(event) {
        console.log({email, password});
        
        firebase.auth().createUserWithEmailAndPassword(email, password)
          .then((user) => {
            // Signed in 
            // ...
            
            history.push('/Quiz')
            console.log(email, password)
            
            firebase.database().ref('users/' + user.uid).set({ email: user.email, password: user.password });
           
          })
          .catch((error) => {
            var errorCode = error.code;
            var errorMessage = error.message;
            // ..
            console.log(errorMessage)
            
          });
          
      }
    return (...)
}