UNPKG

1.07 kBJavaScriptView Raw
1import * as React from 'react';
2import { Text, Platform } from 'react-native';
3import useLinkProps from './useLinkProps';
4
5/**
6 * Component to render link to another screen using a path.
7 * Uses an anchor tag on the web.
8 *
9 * @param props.to Absolute path to screen (e.g. `/feeds/hot`).
10 * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
11 * @param props.children Child elements to render the content.
12 */
13export default function Link({
14 to,
15 action,
16 ...rest
17}) {
18 const props = useLinkProps({
19 to,
20 action
21 });
22
23 const onPress = e => {
24 if ('onPress' in rest) {
25 var _rest$onPress;
26
27 (_rest$onPress = rest.onPress) === null || _rest$onPress === void 0 ? void 0 : _rest$onPress.call(rest, e);
28 }
29
30 props.onPress(e);
31 };
32
33 return /*#__PURE__*/React.createElement(Text, { ...props,
34 ...rest,
35 ...Platform.select({
36 web: {
37 onClick: onPress
38 },
39 default: {
40 onPress
41 }
42 })
43 });
44}
45//# sourceMappingURL=Link.js.map
\No newline at end of file