docs(radio): change demo to hook (#27722)

This commit is contained in:
Tom Xu 2020-11-12 19:54:57 +08:00 committed by GitHub
parent 3ad1887fff
commit 7b6bb4244d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,29 +16,23 @@ A group of radio components.
```jsx ```jsx
import { Radio } from 'antd'; import { Radio } from 'antd';
class App extends React.Component { const App = () => {
state = { const [value, setValue] = React.useState(1);
value: 1,
};
onChange = e => { const onChange = e => {
console.log('radio checked', e.target.value); console.log('radio checked', e.target.value);
this.setState({ setValue(e.target.value);
value: e.target.value,
});
}; };
render() { return (
return ( <Radio.Group onChange={onChange} value={value}>
<Radio.Group onChange={this.onChange} value={this.state.value}> <Radio value={1}>A</Radio>
<Radio value={1}>A</Radio> <Radio value={2}>B</Radio>
<Radio value={2}>B</Radio> <Radio value={3}>C</Radio>
<Radio value={3}>C</Radio> <Radio value={4}>D</Radio>
<Radio value={4}>D</Radio> </Radio.Group>
</Radio.Group> );
); };
}
}
ReactDOM.render(<App />, mountNode); ReactDOM.render(<App />, mountNode);
``` ```