How to display selected text inside MathQuill in the console?

I need to display any content selected in MathQuill in the console. I tried using getSelection(), but it didn’t work. Any other official way to achieve this?

I tried the following:

mathquillDidMount = {(mathField) => {
  mathFieldRef.current = mathField;
}}