I am making a college registration website and I was trying to make a list where the student can choose a certain major to view all the courses in it so I made a list with all the majors and buttons infront of them but everytime i try to use a onClick()
function to go to another page with the courses list it says undefined
.
My code:
import React, { Component } from 'react';
import axios from 'axios';
import { Table } from 'react-bootstrap'
import { Button, Icon } from 'semantic-ui-react';
import { Image, List } from 'semantic-ui-react'
import { left } from '@popperjs/core';
export default class CreateExercise extends Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
onClick(e) {
window.location = '/' + e
}
render() {
return (
<div>
<ul>
{['Adolescence Education: Chemistry (7-12)',
'Adolescence Education: Social Studies (7-12)',
'Biological Sciences',
'Chemistry',
'English',
'History',
'Industrial and Labor Relations',
'Liberal Arts',
'Media and Communications',
'Philosophy and Religion',
'Politics & Economics & Law',
'Spanish Language',
'Visual Arts',
'Adolescence Education: Biology (7-12)',
'Adolescence Education: Mathematics (7-12)',
'Biochemistry',
'Business Administration',
'Childhood Education (1-6)',
'Computer & Information Science',
'Criminology',
'Finance',
'General Studies',
'Health and Society',
'Industrial and Labor Relations',
'Management Information Systems',
'Marketing',
'Mathematics',
'Psychology',
'Sociology',
'Special Education and Childhood Education (1-6)',
'Visual Arts: Electronic Media'
].map(function (item) {
return (
<li key={item}>
{item}
<button type="button" type="button" onClick={onClick({ item })} style={{ position: 'absolute', left: '50%' }} >Click to view courses</button>
</li>
);
})}
</ul>
</div>
)
}
}