728x90
vite proxy ์ค์ ์ ํตํด์ ๋ฐฑ์๋ ์ฐ๋์๋๊ฐ ์ข์
// vite.config ํ์ผ
export default defineConfig({
server: {
proxy: {
'/api': 'http://localhost:8080',
},
},
});
๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ
- features ์ค์ฌ?
src/
โโโ app/
โโโ entities/
โโโ features/
โโโ shared/
โโโ widgets/
โโโ pages/
- ๋ฃฐ์ ๋ง๋ค๊ณ => ์ฝ๋๋ฆฌ๋ทฐ๋ฅผ AI์๊ฒ ๋ถํ.
ํ์ฅ์
- ํ์ ํ์ผ์ด๋ฉด ts๋ก
- /types/Window.ts
any ํ์
interface BootStoreState {
bootStatus: BootStatus;
systemData: any;
errorMessage: string | null;
bootSuccess: (data: any) => void;
...
- ๋ช ํํ ํ์ ์ ์...
- unknown ๋ ์ข์๊ฑด ์๋.
๋์ ํ์ ๊ฒ์ฆ
- ๋์ ์ผ๋ก ์คํ๋๋ response ๋ฐ์ดํฐ์ ํ์ ๋ ๊ฒ์ฆ๊ฐ๋ฅํ๊ฐ?
const SyscallResponseSchema = z.object({
output: z.string(),
});
...
const response = await fetch('์ด์ฉ๊ตฌ...')
const parsed = SyscallResponseSchema.safeParse(response.data);
- ์คํค๋ง์์ ํ์ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
const SyscallResponseSchema = z.object({
output: z.string(),
});
//์คํค๋ง์์ ํ์
์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
type SyscallResponse = z.infer<typeof SyscallResponseSchema>;
...
executeCommand: async (payload: SyscallRequest): Promise<SyscallResponse> => {
...
๋ถํ์ํ props
//props ๋๋จธ์ง๊ฒ๋ค ์ ๋ฌํ ํ์๊ฐ ์๋ค๋ฉด?
function WindowFrame({ title, children, x, y, ...props }: WindowFrameProps) {
Error ์์ํ๊ธฐ
- ErrorBoundary ์ฌ์ฉ.
function App() {
return (
<ErrorBoundary
fallback={(error, reset) => (
<SystemError error={error} onReset={reset} />
)}
>
<Monitor />
</ErrorBoundary>
);
}
- EB ์์
import React from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
// ์์์์ ์๋ฌ ๋ฐ์ ์ ํธ์ถ๋จ
static getDerivedStateFromError(error) {
return { hasError: true };
}
// ๋ก๊น
๋ฑ ๋ถ๊ฐ ์์
๊ฐ๋ฅ
componentDidCatch(error, info) {
console.error("ErrorBoundary caught:", error, info);
}
render() {
if (this.state.hasError) {
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}
export default ErrorBoundary;
response.ok ์๋๋์ ์ง์ ๋ถํ ์ฒ๋ฆฌ
- fetch์ชฝ ์ฝ๋
try {
const response = await fetch('์ด๋๊ฐ ํจ์นญ...');
//handleApiResponse ํธ์ถ(์๋)
const data = await handleApiResponse<SystemBootData>(response);
executeSuccess(data);
} catch (error) {
if (error instanceof ApiException) { //๋ญ ์๋ฌ์ธ์ง ์ ํํ ํ๋ณ๋ ๊ฐ๋ฅ
fail(`[${error.status}] ${error.message}`);
....
}
async function handleApiResponse<T>(response: Response): Promise<T> {
if (!response.ok) {
let errorData: ApiError;
try {
errorData = await response.json();
} catch {
throw new ApiException(
`Server error: ${response.status}`,
response.status
);
}
throw new ApiException(
errorData.message || `Server error: ${response.status}`,
response.status,
errorData.code
);
}
return response.json();
}
- ์๋ฌํด๋์ค
class ApiException extends Error {
constructor(
message: string,
public status: number,
public code?: string
) {
super(message);
this.name = 'ApiException';
}
}
reducer
- redux ์์ ๋์จ ๊ฐ๋ .
- state ๋ณ๊ฒฝ์์ (setXXX)์ด ๋ง๋ค๋ฉด ๊ทธ๋ฐ ๋ฉ์๋๋ฅผ ๋๋ฆฌ๊ธฐ๋ณด๋ค.. reducer๋ฐฉ์์ผ๋ก ํ์ด๋ณด๊ธฐ.
- dispatch({ type, payload })
๋ง์ฐ์ค ๋ฌด๋ธ~
- ๋งค๋ฒ ๋ฆฌ๋ ๋๋ง?
- debounce ์ง์ ๊ตฌํํด์ ์ฌ์ฉ
๋๋ฒ๊น ์ฝ๋์ง์ฐ๊ธฐ
- console.log..
window.console.log = () => alert("์ฃฝ์์ด์ผ..");
๋ฆฌ์กํธ๋ฉ๋ชจ
- ์ปดํฌ๋ํธ ์ ์ฒด๋ฅผ ๊ฐ์ธ์, ๋ฐ๋ props๊ฐ ๋ฐ๋์ง ์์ผ๋ฉด ๊ทธ ์ปดํฌ๋ํธ๋ฅผ ๋ค์ ๋ ๋ํ์ง์์
-
const List = React.memo(function List({ items }) { return items.map(..<li>.); }); - items ๊ฐ ๊ทธ๋๋ก๋ฉด ๊ทธ๋ฅ ์ปดํฌ๋ํธ ๊ทธ๋๋ก ์ฌ์ฌ์ฉ (shallow equality)
์ปค์คํ ํ
SVGR
- SVG๋ฅผ React ์ปดํฌ๋ํธ๋ก ์ฌ์ฉ ๊ฐ๋ฅ. ๊ทธ๋ผ๋ฏ React props๋ก ์ ์ด๋ ๊ฐ๋ฅํ๊ฒ ๊ตฐ..
- ๋น๋๋จ๊ณ์์ svg์ ๋ณด๋ฅผ ์ต์ํ์ผ๋ก ๋น๋.(์์ถ/๊ธฐํ์ ๋ณด ์ ๊ฑฐ๋ฑ)
ํ ์คํธ ์ฝ๋ ๊ตฌํ
- ๋ฌธ์ ๊ฐ ์๋ ๋ถ๋ถ์ ํ ์คํธ๋ฅผ ์ํ
- ๋นUI
- ์๋ฒ๋ก์ง
high number
export const WINDOW_CONSTRAINTS = {
MIN_WIDTH: 300,
MIN_HEIGHT: 200,
DEFAULT_WIDTH: 600,
DEFAULT_HEIGHT: 400,
} as const;
๋น๋ฒํ ์๋ฒ ๋๊ธฐํ
- 1์ด ๋๋๊ทธ -> ์์ญ๋ฒ API์์ฒญ...?
- ๋๊ด์ ์ ๋ฐ์ดํธ (๊ฐ๊ธฐ๋ ์ ์ ๋ก์ปฌ๋ฐ์)
- ๋๋ฐ์ด์ค๋ก ์ ์ก
- ๋๋๊ทธ ์ข ๋ฃ์์๋ ์ฆ์ ๋๊ธฐํ ?(์ต์ข ์ํ๋ง)
- ๋ฐฐ์น๋ก ์ฒ๋ฆฌ.
- ์ ์กํด์ผํ ์ฌ๋ฌ๊ฐ์ง ์ผ๋ค์ ๋ฌถ์ด์ ๋ณด๋ด๋ณผ๊น.
์ ๋๋ฉ์ด์
- requestAnimationFrame ์ฌ์ฉ์ด ์ ์ข์๊น
'๐ ํ๋ก ํธ์๋(FE)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Next.js ์์ํ๊ธฐ (1) | 2026.01.22 |
|---|---|
| ํ๋ก ํธ์๋ ํ ์คํธ ๋๊ตฌ ( MSW, Vitest, React Testing Library ) (0) | 2026.01.21 |
| FE ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ(FE ์ํคํ ์ณ) (0) | 2026.01.20 |
| React ์ํ๊ด๋ฆฌ ( ์ง์ญ, ์ ์ญ, ์๋ฒ ์ปดํฌ๋ํธ ) (0) | 2026.01.20 |
| React ์ฑ๋ฅ ์ต์ ํ (0) | 2026.01.20 |