git: https://github.com/leeyulgok/4-Day2
- 코드 재사용: 중복 코드 제거
- 코드 구조 개선: 컴포넌트에서 상태 관리, API 호출, 이벤트 핸들링 등과 같은 복잡한 로직을 분리함으로써 컴포넌트의 구조를 단순화하고 가독성을 향상
- 테스트 용이성: 독립적으로 테스트할 수 있기 때문에 로직에 대한 단위 테스트를 쉽게 작성
import { useState } from 'react';
// Custom Hook 정의
const useCounter = (initialValue) => {
const [count, setCount] = useState(initialValue);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return { count, increment, decrement };
};
import useCounter from 'hooks/countHook';
const Counter = () => {
const { count, increment, decrement } = useCounter(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
};
본 후기는 유데미-스나이퍼팩토리 10주 완성 프로젝트캠프 학습 일지 후기로 작성 되었습니다.
#프로젝트캠프 #프로젝트캠프후기 #유데미 #스나이퍼팩토리 #웅진씽크빅 #인사이드아웃 #IT개발캠프 #개발자부트캠프 #리액트 #react #부트캠프 #리액트캠프