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
객체들의 배열