Trying to add the login function to the login button but for some reason it says that "Cannot read property 'addEventListener' of null" and I have no idea how to fix it.
I have added the window.onload = function(){} which worked on my other component but doesn't work on this one.
Problem is in this part.
window.onload = function(){
document.getElementById("submit").addEventListener("click", function(){
UserLogin();
})
}
and here is the whole code:
import React from 'react';
import './App.css';
import * as firebase from 'firebase/app';
import 'firebase/auth';
import firebaseConfig from './Config';
//import { BrowserRouter as Router, Route, Link } from "react-router-dom";
firebase.initializeApp(firebaseConfig);
function UserLogin(){
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
//var errorCode = error.code;
//var errorMessage = error.message;
});
}
window.onload = function(){
document.getElementById("submit").addEventListener("click", function(){
UserLogin();
})
}
function Login(){
return(
<div class="start">
<h1>Login</h1>
<div class="input">
<input id="email" type="text" placeholder="email"></input>
<input id="password" type="password" placeholder="password"></input>
<button id="submit">Login</button>
</div>
</div>
)
}
export default Login;