示例如下:
import React from 'react';
import { Radio, Space } from 'antd';
import type { RadioChangeEvent } from 'antd';
const RadioGroupComponent = () => {
const [value, setValue] = React.useState('');
const onChange = (e: RadioChangeEvent, stu: string) => {
console.log('radio checked', e.target.value);
console.log('stu', stu);
setValue(e.target.value);
};
return (
<Radio.Group
onChange={(e) => onChange(e, 'stu123')} // 直接将事件对象 e 传递到 onChange 函数中
value={value}
>
<Space direction="vertical">
<Radio value="孙强">孙强</Radio>
<Radio value="张三">张三</Radio>
<Radio value="李四">李四</Radio>
<Radio value="王五">王五</Radio>
</Space>
</Radio.Group>
);
};
export default RadioGroupComponent;