如何使此类型脚本与 React 教程兼容?
How to make this type script compatible from react tutorial?
在类型脚本中使用时出现不少错误
import { useLocation, NavLink } from "react-router-dom";
function QueryNavLink({ to, ...props }) {
let location = useLocation();
return <NavLink to={to + location.search} {...props} />;
}
TS7031: Binding element 'to' implicitly has an 'any' type.
TS2741: Property 'children' is missing in type '{ to: string; }' but required in type 'NavLinkProps'.
我不太确定如何解决这个问题?
谢谢,
院长
This part of the React Router tutorial 演示了如何编写 <NavLink>
以添加自定义行为,该行为只是“保留”URL 搜索参数。
在那种情况下,道具与 NavLink 相同,因此您也可以输入相同的内容:
function QueryNavLink({ to, ...props }: NavLinkProps) {
let location = useLocation();
return <NavLink to={to + location.search} {...props} />;
}
在类型脚本中使用时出现不少错误
import { useLocation, NavLink } from "react-router-dom";
function QueryNavLink({ to, ...props }) {
let location = useLocation();
return <NavLink to={to + location.search} {...props} />;
}
TS7031: Binding element 'to' implicitly has an 'any' type.
TS2741: Property 'children' is missing in type '{ to: string; }' but required in type 'NavLinkProps'.
我不太确定如何解决这个问题? 谢谢, 院长
This part of the React Router tutorial 演示了如何编写 <NavLink>
以添加自定义行为,该行为只是“保留”URL 搜索参数。
在那种情况下,道具与 NavLink 相同,因此您也可以输入相同的内容:
function QueryNavLink({ to, ...props }: NavLinkProps) {
let location = useLocation();
return <NavLink to={to + location.search} {...props} />;
}