在我的 reactjs 组件中,我收到一个错误:
header.component.tsx(14, 15): An argument for 'e' was not provided.
实际上我应该发送什么参数?
这是组件:
import React, { LinkHTMLAttributes } from 'react';
import { LinkProps, NavLink} from "react-router-dom";
interface NaviState {
show:boolean;
}
export class Header extends React.Component<React.LinkHTMLAttributes<any>, NaviState> {
state:NaviState = {
show:false
}
toggle = (e:React.MouseEvent):void =>{
e.preventDefault();
this.setState(prevState => ({show:!prevState.show}));
}
render() {
return (
<header>
<h1><a className="hidden tantum-logo" href="">Welocome to Tantum website</a></h1>
<div className={"screen " + (this.state.show ? "show":"")}></div>
<nav className={"small " + (this.state.show ? "show" : "")}>
<a className="nav-icon hidden" onClick={this.toggle} href="#">tantum-Menu</a>
<ul>
<li><NavLink activeClassName="active" to="home" onClick={e => this.toggle(e)}>Home</NavLink></li>
<li><NavLink to="about-us" onClick={e => this.toggle(e)}>About us</NavLink></li>
<li><NavLink to="what-we-do" onClick={this.toggle}>What we do</NavLink></li>
<li><NavLink to="projects" onClick={this.toggle}>Projects</NavLink></li>
<li><NavLink to="contacts" onClick={this.toggle}>Contacts</NavLink></li>
<li><a href="#">download <span>browchure</span></a></li>
</ul>
</nav>
</header>
)
}
}
实际上我试图在更改toggle
时调用该函数route
。请指教。做一些改变我的功能。但是“to”没有加载任何页面。
提前致谢。