---
title: "Comment by Karlo B on \"useDebounce in Android's JetPack Compose?\" | Hashnode"
description: "Pretty cool, but this is when you need a debounced effect on state change. This won't work if you want to debounce, say, button clicks or generally function cal"
url: "https://hashnode.com/posts/usedebounce-in-androids-jetpack-compose/64567eb159cc7abf5cac0448/comment/6a540ba6f0937f816ee4b85c"
---

[Discussion](https://hashnode.com/posts/usedebounce-in-androids-jetpack-compose/64567eb159cc7abf5cac0448)

Comment [useDebounce in Android's JetPack Compose?](https://hashnode.com/posts/usedebounce-in-androids-jetpack-compose/64567eb159cc7abf5cac0448)

[Karlo B](https://hashnode.com/@karlo-b)

[Jul 12](https://hashnode.com/posts/usedebounce-in-androids-jetpack-compose/64567eb159cc7abf5cac0448/comment/6a540ba6f0937f816ee4b85c)

Pretty cool, but this is when you need a debounced effect on state change. This won't work if you want to debounce, say, button clicks or generally function calls.

So I took inspiration from your code and created this which would be more in line with Lodash's debounce:

```
@Composable
fun debounced(
    ms: Long,
    coroutineScope: CoroutineScope = rememberCoroutineScope(),
    func: () -> Unit,
): () -> Unit {
    return remember {
        var job: Job? = null

        {
            job?.cancel()

            job = coroutineScope.launch {
                delay(ms.milliseconds)
                func()
            }
        }
    }
}
```
