generated from huibizhang/template-vite-react-ts-tailwind-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersrefactoringworks quite well but needs a refactoringworks quite well but needs a refactoring
Description
Lines 31 to 58 in b0dd564
| const useHttp = ( | |
| requestConfig: RequestConfigType, | |
| handleResponse: (pararm: any) => any, | |
| requestFunc: (url: string, data: any) => Promise<AxiosResponse<any, any>> | |
| ) => { | |
| const [isLoading, setIsLoading] = useState(false); | |
| const [error, setError] = useState(null); | |
| const sendRequest = useCallback( | |
| async (data) => { | |
| setIsLoading(true); | |
| setError(null); | |
| const url = "http://163.180.146.59" + requestConfig.url; | |
| try { | |
| requestFunc(url, data).then((res: any) => { | |
| handleResponse(res.data); | |
| }); | |
| } catch (e: any) { | |
| setError(e.message); | |
| } | |
| setIsLoading(false); | |
| }, | |
| [isLoading, error, requestConfig] | |
| ); | |
| return [isLoading, error, sendRequest]; | |
| }; |
원래 의도는 error, loading 정보를 hook에 담아 모든 httpRequest에 대해 공통으로 처리하려고 하였으나, 모종의 이유로(...) 제대로 동작하지 않는것처럼 보임. 해당 기능을 fix 하고 추가로 error 상황에 대해 공통 컴포넌트로 관리하도록 개선하면 좋을 듯함
https://fe-developers.kakaoent.com/2022/221110-error-boundary/
카카오에서 React16 Error Boundary 기능을 사용해서 에러 핸들링을 한다고 하는데, 참고해서 비슷한 형식으로 개발하면 좋을 듯 합니다.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersrefactoringworks quite well but needs a refactoringworks quite well but needs a refactoring