2023.09.06 계획
- 구글 스타트업 캠퍼스 회원 가입하고, 내일 오후 1시반 까지 모이기
- 9/6 (다같이 생각해오기) + 같이 정하기
- api hook 어떻게 뺄지 (postman 으로 채널 생성, 데이터 가공 어떻게 해야하는지)
- 라우터 주소 어떻게 나눌지
- 그 안의 컴포넌트 어떻게 나눌지 + 공통 컴포넌트로 뭘 뺄 수 있지
- 역할 정하기
- 첫 스프린트 시작하기
비동기 처리
const {data: userList, isLoading} = useQuery( 'UserListQueryKey', fetchPost(..), {} );
- React-query 사용해서 useQuery 훅 호출 시 콜백으로 axios 인스턴스 감싼 함수 넣어주기
- fetchPost
- fetchUser
- fetchNotification
- …
인스턴스는 요청에 뭘 넣어 보내는가에 따라서 생성해주기
const dataToSend = { key1: 'value1', key2: 'value2' }; instance.post('/some-endpoint',dataToSend) .then(function (response) { console.log(response.data); }) .catch(function (error) { console.error(error); }) axios.post('https://some-domain.com/api/some-endpoint', { timeout: 1000, headers: {'X-Custom-Header': 'foobar'}, data: dataToSend }).then(function (response) { console.log(response.data); }) .catch(function (error) { console.error(error); })
axios instance - (baseurl, headers)
fetchPost({ option: ‘create’ , id: …}) // option : 'create' | 'read' | 'update' | 'delete' // update 없음.... url ⇒ post/${option}/${id}
경로 같으면 같은 함수! 다르면 다른함수 .. 그냥 다 다른함수..
1. API HOOK
const api = axios.create({ baseURL: 'https://kdt.frontend.3rd.programmers.co.kr:5001', });

파일명 | 기능 | 담당 | ㅤ |
index | - axios 인스턴스 | 세진 | ㅤ |
auth | - 회원가입: fetchSignUp (POST)
- 로그인: fetchLogIn (POST)
- 로그아웃: fetchLogOut (POST)
- 로그인 인증: fetchAuthUser (GET) | 세진 | ㅤ |
user | - 사용자 목록 불러오기: fetchUsers (GET) map 고려
- 사용자 불러오기: fetchUser (GET) | 지윤 | ㅤ |
post | - 전체 포스트: fetchAllPosts (GET)
- 사용자 전체 포스트: fetchUserPosts (GET)
- 포스트: fetchPost (GET)
- 포스트 생성: fetchCreatePost (POST)
- 포스트 삭제: fetchDeletePost (DELETE) | 주하 | ㅤ |
search | - 포스트 검색: fetchSearchPosts (GET)
- 유저 검색: fetchSearchUsers (GET) | 영준 | ㅤ |
like | - 좋아요 등록: fetchLike (POST)
- 좋아요 취소: fetchUnLike (DELETE) | 영준 | ㅤ |
comment | - 댓글 작성: fetchCreateComment (POST)
- 댓글 삭제: fetchDeleteComment (DELETE) | 민우 | ㅤ |
notification | - 알림 생성: fetchCreateNotification (POST)
- 알림 목록 불러오기: fetchNotifications (GET)
- 알림 읽음 처리: fetchSeenNotifications (PUT) | 민우 | ㅤ |
follow | 특정 유저 팔로우: fetchFollow (POST)
언팔로우 : fetchUnFollow (DELETE) | 영준 | ㅤ |
profile | - 사용자 정보 변경(닉네임): fetchUpdateFullname (PUT)
- 사용자 정보 변경(비밀번호)fetchUpdatePassword (PUT)
- 사용자 이미지 변경: fetchUpdateUserImage (PUT) | 지윤 | ㅤ |
ㅤ | ㅤ | ㅤ | ㅤ |
const data = await instance.get … return data;
// Main => <Route path=’/search/*’ element={<Search/>} /> const Search = ({keyword, sort}) => { useEffect ... () ⇒ route.navigate(’/post’)} return ( <Routes> <Route path=’/post’ element={<PostList keyword={} sort={}/>} /> <Route path=’/user’ element={<UserList keyword={} sort={}/> /> </Routes>) }
2. 라우터 주소
// useBlock.ts // location: 뒤로가기 막을 페이지 location const useBlock = (location: Location | Pathname) => { const history = useHistory() useEffect(() => { const unlisten = history.listen((_, action) => { // 리스너 해제 unlisten() // 뒤로가기 시 동작 if (action === 'POP') { history.push(location) } }) }, [history, location]) } export default useBlock
인증
마이페이지
유저페이지
검색
포스트 작성
포스트
상단 메뉴
공통 컴포넌트 ⇒ 1명
4명 은 api 함수 만들기 fetch 어쩌구..
공통 컴포넌트 : button,
page : Home, Post, Search (검색 결과), MyPage, UserPage
router + data fetch