'A way to check if element overflows in React/Js?

Working on a small Tooltip component. Running into an issue where the tooltip on mobile goes outside the screen and gets cut off. I'm wondering if there's a way to detect that and then use that info to switch the direction so it's not cut off.

Here's an example of what i'm dealing with enter image description here

Some more details - Tooltip component wraps around a word in a 'p' tag and add tooltip on click.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source