Skip to content

Commit

Permalink
FE-73๐Ÿ› useEffect ์˜์กด์„ฑ๋ฐฐ์—ด lint problem ํ•ด๊ฒฐ
Browse files Browse the repository at this point in the history
  • Loading branch information
jisurk committed Jul 24, 2024
1 parent 872d63f commit 6268995
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/pageLayout/Epigram/AddEpigram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { KeyboardEvent, useEffect, useState } from 'react';
import React, { KeyboardEvent, useCallback, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import Header from '@/components/Header/Header';
Expand Down Expand Up @@ -33,19 +33,21 @@ function AddEpigram() {
},
});

// NOTE: ํ•„์ˆ˜ํ•ญ๋ชฉ๋“ค์— ๊ฐ’์ด ๋“ค์–ด์žˆ๋Š”์ง€ ํ™•์ธ
const checkFormEmpty = () => {
// NOTE: ํ•„์ˆ˜ํ•ญ๋ชฉ๋“ค์— ๊ฐ’์ด ๋“ค์–ด์žˆ๋Š”์ง€ ํ™•์ธ ํ•จ์ˆ˜
const checkFormEmpty = useCallback(() => {
const { content, author, tags } = form.getValues();
return content.trim() !== '' && author.trim() !== '' && tags.length > 0;
};
}, [form]);

// NOTE: form๊ฐ’์ด ๋ณ€๊ฒฝ๋ ๋•Œ ํ•„์ˆ˜ํ•ญ๋ชฉ๋“ค์ด ๋“ค์–ด์žˆ๋Š”์ง€ ํ™•์ธ
const watchForm = useCallback(() => {
setIsFormValid(checkFormEmpty());
}, [checkFormEmpty]);

// NOTE: form์˜ ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€
useEffect(() => {
const subscription = form.watch(() => {
setIsFormValid(checkFormEmpty());
});
const subscription = form.watch(watchForm);
return () => subscription.unsubscribe();
}, [form]);
}, [form, watchForm]);

const { currentTag, setCurrentTag, handleAddTag, handleRemoveTag } = useTagManagement(form.setValue, form.getValues, form.setError);

Expand Down

0 comments on commit 6268995

Please sign in to comment.