Skip to content

Commit

Permalink
chore: 생성, 수정 시 새로고침하거나 다른 페이지로 갈 경우 확인 알림 출력
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwhdtjr0457 committed Nov 28, 2023
1 parent 8cd56a4 commit 5bdbfb5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 0 additions & 5 deletions FE/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ function App() {
}, []);

useEffect(() => {
window.addEventListener("beforeunload", (e) => {
e.preventDefault();
e.returnValue = "";
});

window.onpopstate = (event) => {
if (event.state) {
setDiaryState(event.state);
Expand Down
15 changes: 14 additions & 1 deletion FE/src/components/DiaryModal/DiaryCreateModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */

import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { useRecoilValue, useSetRecoilState } from "recoil";
import { useMutation, useQuery } from "react-query";
import styled from "styled-components";
Expand All @@ -25,6 +25,19 @@ function DiaryCreateModal() {
const userState = useRecoilValue(userAtom);
const setDiaryState = useSetRecoilState(diaryAtom);

useEffect(() => {
const handleBeforeUnload = (e) => {
e.preventDefault();
e.returnValue = "";
};

window.addEventListener("beforeunload", handleBeforeUnload);

return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, []);

const closeModal = () => {
setDiaryState((prev) => ({
...prev,
Expand Down
14 changes: 13 additions & 1 deletion FE/src/components/DiaryModal/DiaryUpdateModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from "react";
import React, { useEffect, useRef } from "react";
import { useRecoilValue } from "recoil";
import { useMutation, useQuery } from "react-query";
import styled from "styled-components";
Expand Down Expand Up @@ -55,6 +55,18 @@ function DiaryUpdateModal() {
uuid: diaryState.diaryUuid,
});

useEffect(() => {
const handleBeforeUnload = (e) => {
e.preventDefault();
e.returnValue = "";
};
window.addEventListener("beforeunload", handleBeforeUnload);

return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, []);

const closeModal = () => {
window.history.back();
};
Expand Down

0 comments on commit 5bdbfb5

Please sign in to comment.