I am trying to create copy to Clipboard Component. Here is my code:
import React from 'react';
import logo from './logo.svg';
import './App.css';
class CopyClipboard extends React.Component {
constructor(props) {
super(props);
this.state = { copySuccess: 'Copy to Clipboard!' }
}
copyToClipboard = (e) => {
this.textContent.select();
document.execCommand('copy');
e.target.focus();
this.setState({ copySuccess: 'Copied to Clipboard!' });
};
render() {
return (
<div class="positioning">
{
//if i need
}
<p onClick={this.copyToClipboard} ref={(c) => (this.textContent = c)}>yotam@gmail.com</p> <div class="success">{this.state.copySuccess}</div> </div>
);
}
}
export default CopyClipboard;
I get Parsing error: Unexpected token error. But if i use input tag then its work fine. Where i have done wrong?