If your intention is to use data or data2 as normal html attributes, you can use
accessAttributes = e =>{
let data1=e.currentTarget.getAttribute("data");
let data2=e.currentTarget.getAttribute("data2")
console.log(data1, data2)
}
If you wanted them as data-attributes, you can use
<p data-one={"Very important info"} onClick={this.accessAttributes}
data-two={"A lot of important info"}></p>
accessAttributes = e =>{
let data1=e.currentTarget.dataset.one
let data2=e.currentTarget.dataset.two
console.log(data1, data2)
}
By the way, If your p is in render, there is no content inside p to click. Or at least it should have a height and width.
class App extends React.Component {
constructor(props) {
super(props)
}
accessAttributes = e =>{
let data1=e.currentTarget.getAttribute("data");
let data2=e.currentTarget.getAttribute("data2")
console.log(data1, data2)
}
accessAttributes2 = e =>{
let data1=e.currentTarget.dataset.one;
let data2=e.currentTarget.dataset.two;
console.log(data1, data2)
}
render() {
return (
<div>
<p data={"Very important info"} onClick={this.accessAttributes}
data2={"A lot of important info"}>x</p>
<p data-one={"Very important info"} onClick={this.accessAttributes2}
data-two={"A lot of important info"}>y</p>
</div>
)
}
}
ReactDOM.render(<App />, document.querySelector("#app"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>
<p>?