Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show text that can not be selected/copy using react

I noticed some sites publish text that no one can select or copy. How can this be achieved in React? is it possible? Sometimes I believe they are using some images but this might be a solution that uses too many bytes.

like image 371
Jose Cabrera Zuniga Avatar asked Sep 14 '25 16:09

Jose Cabrera Zuniga


1 Answers

You can use user-select: none; on the elements you don't want to be selectable by the user.

function App() {
  return <div style={{ userSelect: "none" }}>Unselectable text</div>;
}

ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id="root"></div>
like image 126
Tholle Avatar answered Sep 17 '25 06:09

Tholle