docs(switch): change demo to hook (#27618)

This commit is contained in:
Tom Xu 2020-11-08 15:27:13 +08:00 committed by GitHub
parent ef2c494c12
commit 535400f7cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,29 +16,23 @@ Disabled state of `Switch`.
```jsx
import { Switch, Button } from 'antd';
class App extends React.Component {
state = {
disabled: true,
const App = () => {
const [disabled, setDisabled] = React.useState(true);
const toggle = () => {
setDisabled(!disabled);
};
toggle = () => {
this.setState({
disabled: !this.state.disabled,
});
};
render() {
return (
<>
<Switch disabled={this.state.disabled} defaultChecked />
<br />
<Button type="primary" onClick={this.toggle}>
Toggle disabled
</Button>
</>
);
}
}
return (
<>
<Switch disabled={disabled} defaultChecked />
<br />
<Button type="primary" onClick={toggle}>
Toggle disabled
</Button>
</>
);
};
ReactDOM.render(<App />, mountNode);
```