我正在尝试将函数传递给事件侦听器(onClick),但出现以下错误:TypeError:onGenreChange不是函数。我相信我已经将lambda函数正确地传递给了事件监听器。有谁知道为什么这不起作用?谢谢!
class Genres extends Component {
render() {
const { activeGenre, onGenreChange, items, textProperty, valueProperty } = this.props;
const genres = [];
for (let n = 0; n < items.length; n++) {
const genre = items[n][textProperty]
genres.push(<ListGroup.Item onClick={() => {onGenreChange(genre)}} key={genre[valueProperty]} as="li" active={genre === activeGenre}>{genre}</ListGroup.Item>)
}
return (<React.Fragment>
<ListGroup as="ul">
<ListGroup.Item onClick={() => onGenreChange("All Genres")} as="li" active={"All Genres" === activeGenre}>All Genres</ListGroup.Item>
{genres}
</ListGroup>
</React.Fragment>
);
}
}