useLinkPressHandler
declare function useLinkPressHandler(
to: To,
options?: {
replace?: boolean;
state?: any;
}
): (event: GestureResponderEvent) => void;
react-router-native
中对应 useLinkClickHandler
的 useLinkPressHandler
返回一个用于自定义 <Link>
导航的按下事件处理程序。
import { TouchableHighlight } from "react-native";
import { useLinkPressHandler } from "react-router-native";
function Link({
onPress,
replace = false,
state,
to,
...rest
}) {
let handlePress = useLinkPressHandler(to, {
replace,
state,
});
return (
<TouchableHighlight
{...rest}
onPress={(event) => {
onPress?.(event);
if (!event.defaultPrevented) {
handlePress(event);
}
}}
/>
);
}