---
title: "Discussion on \"Show tooltip on selected text using custom hook\" | Hashnode"
description: "Discussion on \"Show tooltip on selected text using custom hook\". Create Medium-like tooltips in React with custom hooks for interactive text selection, accurate positioning, and flexible outputs"
url: "https://hashnode.com/posts/show-tooltip-on-selected-text-using-custom-hook/64f0bcc6f55331966c117b3b"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Show tooltip on selected text using custom hook](https://devcodesthings.hashnode.dev/show-tooltip-on-selected-text-using-custom-hook?utm_source=hashnode&utm_medium=feed)

Create Medium-like tooltips in React with custom hooks for interactive text selection, accurate positioning, and flexible outputs

Aug 31, 2023 · 8 min read · devcodesthings.hashnode.dev  
Updated Sep 3, 2023  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#frontend-development](https://hashnode.com/tag/frontend-development)
-   [#html5](https://hashnode.com/tag/html5)

## Written by

[Dev Shekhawat](https://hashnode.com/@devcodesthings)

@devcodesthings · Delhi, India

  
[View profile](https://hashnode.com/@devcodesthings)

Software Engineer, Hashnode | Frontend Mentor

## Responses 1

Markdown supported · ⌘↵ to post

[Noël Cserépy](https://hashnode.com/@noelcserepy)

[Sep 3, 2023](https://hashnode.com/posts/show-tooltip-on-selected-text-using-custom-hook/64f0bcc6f55331966c117b3b/comment/64f461c76ca042857b453e91)

Very cool! I never knew that selection has so much cool stuff to fiddle around with.

A quick question: wouldn't you want to return an `unsubscribe()` function from the event listener in your `useEffect()` to clean up the listener when the component unmounts?

Thanks for the article :D

[Dev Shekhawat](https://hashnode.com/@devcodesthings)

[Sep 3, 2023](https://hashnode.com/posts/show-tooltip-on-selected-text-using-custom-hook/64f0bcc6f55331966c117b3b/comment/64f461c76ca042857b453e91#reply-64f475cab2147985ab4eda95)

I got too excited it worked I forgot about cleanup. 🤦🏻 Thanks. I will update.
