主分支
分支
主分支 (6.23.1)开发分支
版本
6.23.1v4/5.xv3.x
useLinkPressHandler

useLinkPressHandler

类型声明
declare function useLinkPressHandler(
  to: To,
  options?: {
    replace?: boolean;
    state?: any;
  }
): (event: GestureResponderEvent) => void;

react-router-native 中对应 useLinkClickHandleruseLinkPressHandler 返回一个用于自定义 <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);
        }
      }}
    />
  );
}