MCPcopy
hub / github.com/kriasoft/react-starter-kit / Link

Class Link

src/components/Link/Link.js:14–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14class Link {
15
16 static propTypes = {
17 to: PropTypes.string.isRequired,
18 children: PropTypes.element.isRequired,
19 state: PropTypes.object,
20 onClick: PropTypes.func
21 };
22
23 static handleClick = event => {
24 var allowTransition = true;
25 var clickResult;
26
27 if (this.props && this.props.onClick) {
28 clickResult = this.props.onClick(event);
29 }
30
31 if (isModifiedEvent(event) || !isLeftClickEvent(event)) {
32 return;
33 }
34
35 if (clickResult === false || event.defaultPrevented === true) {
36 allowTransition = false;
37 }
38
39 event.preventDefault();
40
41 if (allowTransition) {
42 const link = event.currentTarget;
43 Location.pushState(
44 this.props && this.props.state || null,
45 this.props && this.props.to || (link.pathname + link.search));
46 }
47 };
48
49 render() {
50 const { to, children, ...props } = this.props;
51 return <a onClick={Link.handleClick.bind(this)} {...props}>{children}</a>;
52 }
53
54}
55
56export default Link;

Callers

nothing calls this directly

Calls 2

isModifiedEventFunction · 0.85
isLeftClickEventFunction · 0.85

Tested by

no test coverage detected