[TypeScript] Props 방식 - useState()

이아현·2025년 2월 6일
0

TypeScript

목록 보기
5/6

useState - list []

type CourseGoal = {
	id: number;
    title: string;
    description: string;
}

export default function App() {
	const [goals, setGoals] = useState<CourseGoal[]>([])
    
   	const handleAddGoal = () => {
    	setGoals((prevGoals)=>{
        	const newGoals: CourseGoal = {
            	id: Math.random(),
                title: "Learn TypeScript",
                description: "Learn it in depth!"
            }
            return [...prevGoals, newGoal]
        })
    }
    
    return (
    	...
    )
}
  • CourseGoal[] : 상태(goals)가 CourseGoal객체들의 배열
profile
PM을 지향하는 FE 개발자 이아현입니다 :)

0개의 댓글