Allow early exit from links

This commit is contained in:
Eric Bailey
2024-02-19 16:58:59 -06:00
parent 640310c7c1
commit 688868a7a9
+6 -3
View File
@@ -51,11 +51,12 @@ type BaseLinkProps = Pick<
warnOnMismatchingTextChild?: boolean warnOnMismatchingTextChild?: boolean
/** /**
* Callback for when the link is pressed. * Callback for when the link is pressed. Prevent default and return `false`
* to exit early and prevent navigation.
* *
* DO NOT use this for navigation, that's what the `to` prop is for. * DO NOT use this for navigation, that's what the `to` prop is for.
*/ */
onPress?: (e: GestureResponderEvent) => void onPress?: (e: GestureResponderEvent) => void | false
/** /**
* Web-only attribute. Sets `download` attr on web. * Web-only attribute. Sets `download` attr on web.
@@ -82,7 +83,9 @@ export function useLink({
const onPress = React.useCallback( const onPress = React.useCallback(
(e: GestureResponderEvent) => { (e: GestureResponderEvent) => {
outerOnPress?.(e) const exitEarlyIfFalse = outerOnPress?.(e)
if (exitEarlyIfFalse === false) return
const requiresWarning = Boolean( const requiresWarning = Boolean(
warnOnMismatchingTextChild && warnOnMismatchingTextChild &&