
์ ์๋ํ๋์ง ํ์ธํ๋ ์์ค์ ๊ฒฝ๊ณ ๋ฌธ์ด ๋ด๋ค.
์ด๋ฉ์ผ/ํจ์ค์๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ ๋ฒํผ์ ๋๋ฅด๋ ๊ฒฝ๊ณ ๋ฌธ์ด ๋ด๋ค.

โ ๏ธ Warning: Can't perform a React state update on an unmounted component.
This is no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
at Auth (...URL)
๋ง์ธ ์ฆ์จ, ๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์์ ๋ํด ๋ฆฌ์กํธ state๋ฅผ ์ ๋ฐ์ดํธ ํ ์ ์๋ค๋ ๊ฒฝ๊ณ ์ด๋ค. ๋น๋๊ธฐ ๋ก์ง ๋๋ฌธ์ ์ด๋ฐ ํ์์ด ๋ฐ์ํ๋๋ฐ, ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋์ถ๋ ์๋ ์๊ธฐ ๋๋ฌธ์ ๊ณ ์น๋ ๊ฒ์ด ์ข๋ค๊ณ ํ๋ค.
๋ฌธ์ ๊ฐ ๋๋ URL์ ๋๋ฌ ๋ดค๋๋ Auth.js์ ๊ฐ์ ๋ฒํผ์ ๋๋ฅผ ๋, ๋ผ์ฐํธ๋ ์ด๋ฏธ ์ด๋๋๋๋ฐ, ๊ทธ๋ฌ๊ณ ๋์ setNewAccount(false)๋ก state๋ฅผ ๋ณ๊ฒฝํ๋ ค๊ณ ํ๋๊ฒ ๋ฌธ์ ์๋ค.
//form์ ์ฌ์ฉํ๋ ์ด๋ฒคํธ
const onSubmit = async (event) => {
event.preventDefault();
//newAccount๊ฐ ์ฐธ์ด๋ฉด ๊ณ์ ์๋ก ๋ง๋ค๊ณ , ๊ฑฐ์ง์ด๋ฉด ๋ก๊ทธ์ธํ๊ธฐ
try {
if (newAccount) {
await createUserWithEmailAndPassword(auth, email, password);
setNewAccount(false); //โ ๏ธ ์๋ฌ ๋ฐ์ ์ง์ : ๋ผ์ฐํฐ ์ด๋ ํ state ๋ณ๊ฒฝํ๊ธฐ ๋๋ฌธ
} else {
await signInWithEmailAndPassword(auth, email, password);
}
} catch (error) {
setError(error.message);
}
};
์ด๋ฏธ ๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์์ ๋ํด์๋ ๋ฆฌ์กํธ๊ฐ state๋ฅผ ์
๋ฐ์ดํธ ํ ์ ์๊ธฐ ๋๋ฌธ์
ํด๋ฆฐ์
ํ์
์ ์ฌ์ฉํ์.
//form์ ์ฌ์ฉํ๋ ์ด๋ฒคํธ
const onSubmit = async (event) => {
event.preventDefault();
//newAccount๊ฐ ์ฐธ์ด๋ฉด ๊ณ์ ์๋ก ๋ง๋ค๊ณ , ๊ฑฐ์ง์ด๋ฉด ๋ก๊ทธ์ธํ๊ธฐ
try {
if (newAccount) {
await createUserWithEmailAndPassword(auth, email, password);
//โ ๏ธ ์๋ฌ ๋ฐ์ ์ง์ : ๋ผ์ฐํฐ์ด๋ ํ state ๋ณ๊ฒฝํ๊ธฐ ๋๋ฌธ, ๋ฐ๋ผ์ โ
์ญ์
//โ ๏ธ setNewAccount(false);
} else {
await signInWithEmailAndPassword(auth, email, password);
}
} catch (error) {
setError(error.message);
}
};
//โ
ํด๊ฒฐ: ํด๋ฆฐ์
ํ์
๋ฃ์
useEffect(() => {
return () => setNewAccount(false);
}, []);