【发布时间】:2018-08-30 14:23:58
【问题描述】:
每当我使用它时,即使我没有单击按钮,侧边栏也会始终打开。换句话说,每当我刷新浏览器时,侧边栏就已经打开了。我希望它关闭,只有当我单击按钮时,侧边栏才会打开。
但我希望它按命令打开和关闭。我尝试使用支持的道具,但仍然没有运气:(。
我正在使用这个顺便说一句https://github.com/balloob/react-sidebar#installation
这是我的App.js 文件:
import React from "react";
import Sidebar from "react-sidebar";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
sidebarOpen: true
};
this.onSetSidebarOpen = this.onSetSidebarOpen.bind(this);
}
onSetSidebarOpen(open) {
this.setState({ sidebarOpen: open });
}
render() {
return (
<Sidebar
sidebar={<div><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b><b>Sidebar content</b></div>}
open={this.state.sidebarOpen}
onSetOpen={this.onSetSidebarOpen}
styles={{ sidebar: { background: "white" } }}
>
<button onClick={() => this.onSetSidebarOpen(true)}>
Open sidebar
</button>
</Sidebar>
);
}
}
export default App;
【问题讨论】:
标签: javascript reactjs debugging slider