mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
docs(switch): change demo to hook (#27618)
This commit is contained in:
parent
ef2c494c12
commit
535400f7cd
@ -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);
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user