Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDD-86] 상태관리 라이브러리 추가 (순수 세팅 시간 1h/8h) (상태 관리 고민시간 4h/???) #25

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 141 additions & 4 deletions FE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion FE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
"@emotion/babel-preset-css-prop": "^11.11.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@tanstack/react-query": "^5.8.1",
"@tanstack/react-query-devtools": "^5.8.1",
"axios": "^1.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0"
"react-router-dom": "^6.18.0",
"recoil": "^0.7.7"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
Expand Down
18 changes: 14 additions & 4 deletions FE/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { Global, ThemeProvider } from '@emotion/react';
import { theme } from '@styles/theme';
import _global from '@styles/_global';
import AppRouter from '@/AppRouter'; // AppRouter를 임포트합니다.
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { RecoilRoot } from 'recoil';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const queryClient = new QueryClient();

function App() {
return (
<ThemeProvider theme={theme}>
<Global styles={_global} />
<AppRouter />
</ThemeProvider>
<QueryClientProvider client={queryClient}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 그냥 궁금한건데 react-query와 recoil의 wrapping 순서가 의미가 있을까요?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별 의미는 없습니다~

<ReactQueryDevtools initialIsOpen={false} />
<RecoilRoot>
<ThemeProvider theme={theme}>
<Global styles={_global} />
<AppRouter />
</ThemeProvider>
</RecoilRoot>
</QueryClientProvider>
);
}

Expand Down
50 changes: 50 additions & 0 deletions FE/src/apis/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { BASE_URL } from '@/constants/api';
import axios, { AxiosError } from 'axios';

const api = (() => {
const axiosInstance = axios.create({
baseURL: BASE_URL,
timeout: 3000,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
},
});

axiosInstance.interceptors.response.use(
(response) => {
return response;
},
// TODO: console은 dev 환경에서만 동작해야 하고 실제 prod환경에서는 어떻게 처리할지 논의 해봐야함
(error: AxiosError) => {
if (error.code === 'ECONNABORTED') {
alert('서버에 이상이 있습니다.');
}
switch (error.response?.status) {
case 401:
console.warn('401: 인증정보 없음');
break;
case 403:
console.warn('403: 권한 없음');
break;
case 404:
console.warn('404: 대상을 찾지 못함');
break;
case 500:
case 501:
case 502:
case 503:
case 504:
console.warn(`${error.response?.status}: 서버 오류`);
break;
default:
console.error(`${error.response?.status}: unhandled error!`);
break;
}
return Promise.reject(error);
}
);
return axiosInstance;
})();

export default api;
2 changes: 1 addition & 1 deletion FE/src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BASEURL = '';
export const BASE_URL = '';

type Id = number;

Expand Down
Loading