From da6e4cbd7c0aaab788dd4007a9e6d3cbd172bc45 Mon Sep 17 00:00:00 2001 From: arvind Date: Fri, 19 Feb 2021 02:47:19 +1000 Subject: [PATCH 1/5] fixed warning for state changes for unmounted component in Login and Signup --- .gitignore | 1 + src/components/Login.js | 38 ++++++++++++++++++------------------ src/components/Signup.js | 42 ++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 4d29575..6e8f746 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies +.env /node_modules /.pnp .pnp.js diff --git a/src/components/Login.js b/src/components/Login.js index 53ec8b7..c8990f8 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -1,29 +1,29 @@ -import React, { useRef, useState } from "react" -import { Form, Button, Card, Alert } from "react-bootstrap" -import { useAuth } from "../contexts/AuthContext" -import { Link, useHistory } from "react-router-dom" +import React, { useRef, useState } from "react"; +import { Form, Button, Card, Alert } from "react-bootstrap"; +import { useAuth } from "../contexts/AuthContext"; +import { Link, useHistory } from "react-router-dom"; export default function Login() { - const emailRef = useRef() - const passwordRef = useRef() - const { login } = useAuth() - const [error, setError] = useState("") - const [loading, setLoading] = useState(false) - const history = useHistory() + const emailRef = useRef(); + const passwordRef = useRef(); + const { login } = useAuth(); + const [error, setError] = useState(""); + const [loading, setLoading] = useState(false); + const history = useHistory(); async function handleSubmit(e) { - e.preventDefault() + e.preventDefault(); try { - setError("") - setLoading(true) - await login(emailRef.current.value, passwordRef.current.value) - history.push("/") + setError(""); + setLoading(true); + await login(emailRef.current.value, passwordRef.current.value); + setLoading(false); + history.push("/"); } catch { - setError("Failed to log in") + setLoading(false); + setError("Failed to log in"); } - - setLoading(false) } return ( @@ -54,5 +54,5 @@ export default function Login() { Need an account? Sign Up - ) + ); } diff --git a/src/components/Signup.js b/src/components/Signup.js index 546b77b..dcf54c7 100644 --- a/src/components/Signup.js +++ b/src/components/Signup.js @@ -1,34 +1,34 @@ -import React, { useRef, useState } from "react" -import { Form, Button, Card, Alert } from "react-bootstrap" -import { useAuth } from "../contexts/AuthContext" -import { Link, useHistory } from "react-router-dom" +import React, { useRef, useState } from "react"; +import { Form, Button, Card, Alert } from "react-bootstrap"; +import { useAuth } from "../contexts/AuthContext"; +import { Link, useHistory } from "react-router-dom"; export default function Signup() { - const emailRef = useRef() - const passwordRef = useRef() - const passwordConfirmRef = useRef() - const { signup } = useAuth() - const [error, setError] = useState("") - const [loading, setLoading] = useState(false) - const history = useHistory() + const emailRef = useRef(); + const passwordRef = useRef(); + const passwordConfirmRef = useRef(); + const { signup } = useAuth(); + const [error, setError] = useState(""); + const [loading, setLoading] = useState(false); + const history = useHistory(); async function handleSubmit(e) { - e.preventDefault() + e.preventDefault(); if (passwordRef.current.value !== passwordConfirmRef.current.value) { - return setError("Passwords do not match") + return setError("Passwords do not match"); } try { - setError("") - setLoading(true) - await signup(emailRef.current.value, passwordRef.current.value) - history.push("/") + setError(""); + setLoading(true); + await signup(emailRef.current.value, passwordRef.current.value); + setLoading(false); + history.push("/"); } catch { - setError("Failed to create an account") + setLoading(false); + setError("Failed to create an account"); } - - setLoading(false) } return ( @@ -60,5 +60,5 @@ export default function Signup() { Already have an account? Log In - ) + ); } From 88ca4cb11348aa8357b995235eb025517990f879 Mon Sep 17 00:00:00 2001 From: Arvind <65374628+Arvind90475@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:27:51 +1000 Subject: [PATCH 2/5] fixed unnecessary changes --- src/components/Login.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/Login.js b/src/components/Login.js index c8990f8..ba2fe37 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -1,28 +1,28 @@ -import React, { useRef, useState } from "react"; -import { Form, Button, Card, Alert } from "react-bootstrap"; -import { useAuth } from "../contexts/AuthContext"; -import { Link, useHistory } from "react-router-dom"; +import React, { useRef, useState } from "react" +import { Form, Button, Card, Alert } from "react-bootstrap" +import { useAuth } from "../contexts/AuthContext" +import { Link, useHistory } from "react-router-dom" export default function Login() { - const emailRef = useRef(); - const passwordRef = useRef(); - const { login } = useAuth(); - const [error, setError] = useState(""); - const [loading, setLoading] = useState(false); - const history = useHistory(); + const emailRef = useRef() + const passwordRef = useRef() + const { login } = useAuth() + const [error, setError] = useState("") + const [loading, setLoading] = useState(false + const history = useHistory async function handleSubmit(e) { - e.preventDefault(); + e.preventDefault try { - setError(""); - setLoading(true); - await login(emailRef.current.value, passwordRef.current.value); - setLoading(false); - history.push("/"); + setError("") + setLoading(true + await login(emailRef.current.value, passwordRef.current.value) + setLoading(false) + history.push("/") } catch { - setLoading(false); - setError("Failed to log in"); + setLoading(false) + setError("Failed to log in") } } @@ -54,5 +54,5 @@ export default function Login() { Need an account? Sign Up - ); + } From 16d0a4a797ef37f226512497f40d58542104820b Mon Sep 17 00:00:00 2001 From: Arvind <65374628+Arvind90475@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:28:42 +1000 Subject: [PATCH 3/5] Update Login.js --- src/components/Login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Login.js b/src/components/Login.js index ba2fe37..aa497fb 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -8,8 +8,8 @@ export default function Login() { const passwordRef = useRef() const { login } = useAuth() const [error, setError] = useState("") - const [loading, setLoading] = useState(false - const history = useHistory + const [loading, setLoading] = useState(false) + const history = useHistory() async function handleSubmit(e) { e.preventDefault From 5cea6c0821293e3528e2a1768ee57e55d6ba6846 Mon Sep 17 00:00:00 2001 From: Arvind <65374628+Arvind90475@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:29:32 +1000 Subject: [PATCH 4/5] Update Login.js --- src/components/Login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Login.js b/src/components/Login.js index aa497fb..0541b28 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -12,11 +12,11 @@ export default function Login() { const history = useHistory() async function handleSubmit(e) { - e.preventDefault + e.preventDefault() try { setError("") - setLoading(true + setLoading(true) await login(emailRef.current.value, passwordRef.current.value) setLoading(false) history.push("/") From 0103ad6476ab01f060aef45066b63e0277d037ea Mon Sep 17 00:00:00 2001 From: Arvind <65374628+Arvind90475@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:30:30 +1000 Subject: [PATCH 5/5] Update Signup.js --- src/components/Signup.js | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/components/Signup.js b/src/components/Signup.js index dcf54c7..eda657c 100644 --- a/src/components/Signup.js +++ b/src/components/Signup.js @@ -1,33 +1,33 @@ -import React, { useRef, useState } from "react"; -import { Form, Button, Card, Alert } from "react-bootstrap"; -import { useAuth } from "../contexts/AuthContext"; -import { Link, useHistory } from "react-router-dom"; +import React, { useRef, useState } from "react" +import { Form, Button, Card, Alert } from "react-bootstrap" +import { useAuth } from "../contexts/AuthContext" +import { Link, useHistory } from "react-router-dom" export default function Signup() { - const emailRef = useRef(); - const passwordRef = useRef(); - const passwordConfirmRef = useRef(); - const { signup } = useAuth(); - const [error, setError] = useState(""); - const [loading, setLoading] = useState(false); - const history = useHistory(); + const emailRef = useRef() + const passwordRef = useRef() + const passwordConfirmRef = useRef() + const { signup } = useAuth() + const [error, setError] = useState("") + const [loading, setLoading] = useState(false) + const history = useHistory() async function handleSubmit(e) { - e.preventDefault(); + e.preventDefault() if (passwordRef.current.value !== passwordConfirmRef.current.value) { - return setError("Passwords do not match"); + return setError("Passwords do not match") } try { - setError(""); - setLoading(true); - await signup(emailRef.current.value, passwordRef.current.value); - setLoading(false); - history.push("/"); + setError("") + setLoading(true) + await signup(emailRef.current.value, passwordRef.current.value) + setLoading(false) + history.push("/") } catch { - setLoading(false); - setError("Failed to create an account"); + setLoading(false) + setError("Failed to create an account") } } @@ -60,5 +60,5 @@ export default function Signup() { Already have an account? Log In - ); + ) }