定义了一个无状态组件
import React,{useState} from 'react';
import { Image } from 'antd';
import { useHistory } from 'react-router-dom';
import "./MenuBar.scss";
function ListItem(props)?{
const hisorty = useHistory();
const i = props.value;
handleClick =?(i) => {
console.log(i)
};
return (
<div className="block" onClick={this.handleClick(i)}>
<img src={i.url} style={{ height: '120px', width: '120px' }} />
</div>
)
}
export default function MenuBar(props)?{
const numbers = props.menu;
const listItems = numbers.map((item, index) =>
<ListItem key={index} value={item} />
);
return (
<ul>
{listItems}
</ul>
);
}
编译的时候
一直提示 handleClick事件未定义 换了好几种写法都不可以
网上查了一下说 是babel支持的问题 需要改写配置文件 不知道这个地方要怎么改?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…