I have a React application which displays some spans:
Hello my name is &l
There is no React-specific solution for this. Just use window.getSelection API.
To output highlighted text run window.getSelection().toString()
window.getSelection().toString()