I'm learning Typescript and I'm trying to write the proper syntax to define an interface for the state variable classRecord but I can't seem to get it right.
interface ClassInterfaceObject {
id: string
className: string
studentsInClass: string[]
}
export interface ClassRecords {
ClassInterfaceObject: []
}
const [classRecord, setClassRecord] = useState<ClassRecords>([
{
id: '1000',
className: 'CS101',
studentsInClass: ['Tom', 'Bernard', 'Joseph'],
},
{
id: '1001',
className: 'CS102',
studentsInClass: ['Bruce', 'Mary', 'Jack'],
},
{
id: '1002',
className: 'CS103',
studentsInClass: ['Janet', 'Mercy', 'Sally'],
},
])
My end goal is to have the data in the following format:
0: {id: '1000', className: 'CS101', studentsInClass: Array(3)...}
1: {id: '1001', className: 'CS102', studentsInClass: Array(3)...}
2: {id: '1002', className: 'CS103', studentsInClass: Array(3)...}