Expo Router: Type of href of the Link ? #27252
Unanswered
welschmoor
asked this question in
Archived: Questions
Replies: 2 comments 4 replies
-
import { type Href } from 'expo-router';
export interface TouchableScaleProps<T> extends PressableProps {
activeScale?: number;
disabled?: boolean;
href?: Href<T>;
}
export interface LinkScaleProps<T> extends TouchableScaleProps<T> {
href: TouchableScaleProps<T>['href'];
}
export function LinkScale<T>({ href, onPress, ...props }: LinkScaleProps<T>) {
const resolvedHref = useMemo(() => {
if (href == null) {
throw new Error('Link: href is required');
}
return resolveHref(href);
}, [href]);
const linkProps = useLinkToPathProps({ href: resolvedHref });
return (
<TouchableScale
{...props}
onPress={(event) => {
onPress?.(event);
linkProps.onPress();
}}
/>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I am struggling to put a type on the href that I want passed through Props to a Link that I wrap.
Am I close? :
Typed routes, I of course want to preserve type safety, so I can't use string
Beta Was this translation helpful? Give feedback.
All reactions