Разбираюсь с чужим кодом.
Наткнулся на такое:
Код компонента:
import React, { Component } from 'react';
export default class TabSwitchItem extends Component {
constructor(props) {
super(props);
}
clickHandler = (a, event) => {
console.log(a);
console.log(event);
console.log(event.preventDefault());
};
let { item } = this.props;
render() {
const result = <a onClick={() => this.clickHandler('1', event)}>{item.title}</a>;
return (
<React.Fragment>
{ result }
</React.Fragment>
)
}
}
Результат:
1
MouseEvent {isTrusted: true, screenX: 1771, screenY: 192, clientX: 1771, clientY: 58, …}
altKey: false
bubbles: true
button: 0
buttons: 0
cancelBubble: false
cancelable: true
clientX: 1771
clientY: 58
composed: true
ctrlKey: false
currentTarget: null
defaultPrevented: true
detail: 1
eventPhase: 0
fromElement: null
isTrusted: true
layerX: 80
layerY: 21
metaKey: false
movementX: 0
movementY: 0
offsetX: 81
offsetY: 22
pageX: 1771
pageY: 245
altKey: falsebubbles: truebutton: 0buttons: 0cancelBubble: falsecancelable: trueclientX: 1771clientY: 58composed: truectrlKey: falsecurrentTarget: nulldefaultPrevented: truedetail: 1eventPhase: 0fromElement: nullisTrusted: truelayerX: 80layerY: 21metaKey: falsemovementX: 0movementY: 0offsetX: 81offsetY: 22pageX: 1771pageY: 245path: (22) [a.b-tabs-header__item, div.b-tabs-header__item-wrap, div.b-tabs-header__items-list, div.b-tabs-header__wrapper, div.b-tabs-header.b-tabs-header_adapt_default.b-tabs-header_theme_folder, div.b-map-data__tabs-header, div.b-map-data__wrapper, div.b-map-data.b-map-data_adapt_default, div.b-map__map-data, div.b-map__info-block, div.b-map__wrapper, div.b-map.b-map_adapt_default.js-init, div.page__map, div.page__map-block, div.page__container.page__container_map, main.page__main-holder, div.page__main-content-wrap, div#root, body.page, html.pp-mod_support_spam, document, Window]relatedTarget: nullreturnValue: falsescreenX: 1771screenY: 192shiftKey: falsesourceCapabilities: InputDeviceCapabilitiesfiresTouchEvents: false__proto__: InputDeviceCapabilitiessrcElement: a.b-tabs-header__itemtarget: a.b-tabs-header__itemtimeStamp: 4215.439999999944toElement: a.b-tabs-header__itemtype: "click"view: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}which: 1x: 1771y: 58__proto__: MouseEvent
TabSwitchItem.js:12
undefined
То есть отсутствует event.preventDefault().