javascript - React Link / href 的 Typescript onclick 事件类型 - 类型“IntrinsicAttributes 和 LinkProps”上不存在属性“onClick”
问题描述
我只是想在 TS 中添加一个简单的点击事件。
功能
const displayNewClaim = (event: React.MouseEvent<HTMLElement>) => {
event.preventDefault();
};
TS错误
Type '{ children: string; to: string; styles: "button"; onClick: (event: MouseEvent<HTMLElement, MouseEvent>) => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps & { children?: ReactNode; }'.
Property 'onClick' does not exist on type 'IntrinsicAttributes & LinkProps & { children?: ReactNode; }'. TS2322
81 | <input type="file" name="fileupload" /> <button>Upload CSV</button>
82 | </form>
> 83 | <Link to="/new-claim" styles="button" onClick={displayNewClaim}>
| ^
84 | New claim
85 | </Link>
86 | </Header>
解决方案
在这里你可以做类似的事情
<Link styles="button" onClick={(e) => displayNewClaim(e)}>New claim</Link>
功能
进口
import { navigate } from "gatsby"
功能
const displayNewClaim = (event: React.MouseEvent<HTMLElement>) => {
event.preventDefault();
navigate('/new-claim')
};
推荐阅读
- django - Django RESTApi 使用 ForeignKey 作为过滤器仍然会产生错误
- python - ortools / 线性规划 - 最小化跨供应商的购物篮成本
- azure-data-factory - 使用数据流以分层格式存储文件时出现 Azure 数据工厂错误
- python-3.x - Tensorflow 2.2.0 无法加载动态库“libcudnn.so.7”
- sql-server - SSIS 加载带有动态列的 Excel 文件
- javascript - Vue:全局 v 指令在一个组件中工作,但不在另一个组件中
- informatica - Informatica 中的更新大约需要很长时间。(38 小时)
- numpy - 解决apt_pkg和Numpy安装问题
- session - NextJS 和 NextAuth 会话用户对象由于 [...nextauth.ts] 被触发重新编译而丢失
- java - TargetDataline 返回 -1(Audiosystem.NOT_SPECIFIED)