Reactjs 在这种情况下,如何在react js中创建sidenav移动链接?
我想让sidenav mobile在单击时显示 我试图使用jquery,但不知道如何在webpack中配置Reactjs 在这种情况下,如何在react js中创建sidenav移动链接?,reactjs,Reactjs,我想让sidenav mobile在单击时显示 我试图使用jquery,但不知道如何在webpack中配置 const SignedOutLinks = () => { return ( <div> <NavLink to="#" className="sidenav-trigger nav-wrapper" data-target="mobile-links"> <i class
const SignedOutLinks = () => {
return (
<div>
<NavLink to="#" className="sidenav-trigger nav-wrapper" data-target="mobile-links">
<i className="material-icons">menu</i>
</NavLink>
<ul className="right hide-on-med-and-down">
<li className="waves-effect waves-light">
<NavLink to="/signup">Signup</NavLink>
</li>
<li className="waves-effect waves-light">
<NavLink to="/signin">Login</NavLink>
</li>
</ul>
<ul className="sidenav" id="mobile-links">
<li className="waves-effect waves-light">
<NavLink to="/signup">Signup</NavLink>
</li>
<li className="waves-effect waves-light">
<NavLink to="/signin">Login</NavLink>
</li>
</ul>
</div>
);
};
const SignedOutLinks=()=>{
返回(
菜单
-
报名
-
登录
-
报名
-
登录
);
};
如果你想写它,这是我编写的一些代码:
或
反应:
class Drawer extends React.Component{
constructor(props){
super(props)
this.state = {
open: false,
}
}
handleDrawer(){
let currentState = this.state.open
this.setState({open: !currentState})
}
componentDidMount(){
if (this.state.open = true){
document.addEventListener("keydown", (event) => {
if (event.keyCode === 27){
this.setState({open: false})
}
})
}
}
handleClickOut(){
if(this.state.open === true){
this.setState({open: false})
}
}
render(){
console.log(this.state)
return (
<div>
<div
onClick={this.handleClickOut.bind(this)}
className={this.state.open ? "deactive" : "container"}>
<button onClick={this.handleDrawer.bind(this)}>Click on me to see the
drawer</button>
</div>
<div className={this.state.open ? "active" : "drawer"}>Hellllo i'm a
drawer</div>
</div>
)
}
}
export default Drawer
或者,如果您想对其进行完整编码,您可以使用framework如果您想编写它,这是我编写的一些代码: 或 反应:
class Drawer extends React.Component{
constructor(props){
super(props)
this.state = {
open: false,
}
}
handleDrawer(){
let currentState = this.state.open
this.setState({open: !currentState})
}
componentDidMount(){
if (this.state.open = true){
document.addEventListener("keydown", (event) => {
if (event.keyCode === 27){
this.setState({open: false})
}
})
}
}
handleClickOut(){
if(this.state.open === true){
this.setState({open: false})
}
}
render(){
console.log(this.state)
return (
<div>
<div
onClick={this.handleClickOut.bind(this)}
className={this.state.open ? "deactive" : "container"}>
<button onClick={this.handleDrawer.bind(this)}>Click on me to see the
drawer</button>
</div>
<div className={this.state.open ? "active" : "drawer"}>Hellllo i'm a
drawer</div>
</div>
)
}
}
export default Drawer
或者,如果您想对其进行完整编码,您可以使用framework为什么在使用react时要使用jquery?这破坏了另一个图书馆的意义。我认为它会更有效。有没有想过用javascript代替jquery?为什么在使用react时要使用jquery?这破坏了另一个图书馆的意义。我认为它会更有效。有没有想过用javascript代替jquery?