---
title: "Discussion on \"A Simple UseEffect trick\" | Hashnode"
description: "Discussion on \"A Simple UseEffect trick\". One of the important things that we learn about useEffect is that we need to pass on dependency to the useEffect to make it run conditionally. But the useEffect runs on every hard refresh even after having a dependency. Let us understand this through..."
url: "https://hashnode.com/posts/a-simple-useeffect-trick/62035894b6c216065a35a983"
---

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

Discussion

# [A Simple UseEffect trick](https://hashnode.com/post/a-simple-useeffect-trick?utm_source=hashnode&utm_medium=feed)

One of the important things that we learn about useEffect is that we need to pass on dependency to the useEffect to make it run conditionally. But the useEffect runs on every hard refresh even after having a dependency. Let us understand this through...

Feb 9, 2022 · 2 min read · hashnode.com  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#react-native](https://hashnode.com/tag/react-native)
-   [#reacthooks](https://hashnode.com/tag/reacthooks)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Gitartha Kashyap](https://hashnode.com/@Withewolf)

@Withewolf

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

On the journey to become a Self taught MERN stack developer

## Responses 1

Markdown supported · ⌘↵ to post

[Faheem Khan](https://hashnode.com/@FaheemKhancodes)

[Feb 9, 2022](https://hashnode.com/posts/a-simple-useeffect-trick/62035894b6c216065a35a983/comment/62038c56b6c216065a35b15d)

Thank you for your effort but I didn't get what problem this article trying to address.

1.  If you want to run certain function only when user clicks then put that function inside the click event handler.
2.  You want to achieve that useEffect should not run after first render but even after your workaround it still runs, just your if condition is passing hence else block is not executing in first render.
