【发布时间】:2020-05-05 17:52:26
【问题描述】:
我正在创建一个 reactjs 网络应用程序,我想在其中使用折叠功能。所以我安装了 reactstrap 依赖并从那里导入“Collapse”组件。但它在我的代码中不起作用。
import { Component } from "react";
import React from "react";
import { Collapse, Navbar } from "reactstrap";
class Main extends Component {
constructor(props) {
super(props);
this.state = {
open: false
};
}
show() {
this.setState({
open: !this.state.open
});
}
render() {
return (
<>
<button onClick={() => this.show()}>Show</button>
<Collapse isOpen={this.state.open}>
<Navbar>hello</Navbar>
</Collapse>
</>
);
}
}
export default Main;
查看demo这里。
【问题讨论】:
标签: javascript reactjs web reactstrap