diff --git a/components/menu/demo/sider-current.md b/components/menu/demo/sider-current.md index 343a46d398..372ca04782 100755 --- a/components/menu/demo/sider-current.md +++ b/components/menu/demo/sider-current.md @@ -19,57 +19,46 @@ import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/ico const { SubMenu } = Menu; -class Sider extends React.Component { - // submenu keys of first level - rootSubmenuKeys = ['sub1', 'sub2', 'sub4']; +// submenu keys of first level +const rootSubmenuKeys = ['sub1', 'sub2', 'sub4']; - state = { - openKeys: ['sub1'], - }; +const Sider = () => { + const [openKeys, setOpenKeys] = React.useState(['sub1']); - onOpenChange = openKeys => { - const latestOpenKey = openKeys.find(key => this.state.openKeys.indexOf(key) === -1); - if (this.rootSubmenuKeys.indexOf(latestOpenKey) === -1) { - this.setState({ openKeys }); + const onOpenChange = keys => { + const latestOpenKey = keys.find(key => openKeys.indexOf(key) === -1); + if (rootSubmenuKeys.indexOf(latestOpenKey) === -1) { + setOpenKeys(keys); } else { - this.setState({ - openKeys: latestOpenKey ? [latestOpenKey] : [], - }); + setOpenKeys(latestOpenKey ? [latestOpenKey] : []); } }; - render() { - return ( - - } title="Navigation One"> - Option 1 - Option 2 - Option 3 - Option 4 + return ( + + } title="Navigation One"> + Option 1 + Option 2 + Option 3 + Option 4 + + } title="Navigation Two"> + Option 5 + Option 6 + + Option 7 + Option 8 - } title="Navigation Two"> - Option 5 - Option 6 - - Option 7 - Option 8 - - - } title="Navigation Three"> - Option 9 - Option 10 - Option 11 - Option 12 - - - ); - } -} + + } title="Navigation Three"> + Option 9 + Option 10 + Option 11 + Option 12 + + + ); +}; ReactDOM.render(, mountNode); ```