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