Those don't have the same behavior, or at least may only in a limited toy example where re-renders are not being triggered by other rendering activity that would cause this component to re-render. If you don't use the useEffect then your playSound function will execute on every re-render of the component when the condition is true, regardless of this prop coming in again as true when it is already (or when a different truthy value for it comes in). If you do the useEffect with the boolean as a dependency then the code in it (your conditional execution of playSound) will only execute upon transitioning from true-to-false or false-to-true, but never for a transition from false-to-false or true-to-true. Answer from dreadwail on reddit.com
🌐
GitHub
github.com › facebook › react › issues › 22272
Feature Request - useEffect - Provide boolean values on whether dependency has changed. · Issue #22272 · facebook/react
September 8, 2021 - Couldn't find this feature request already (though it sounds like you probably definitely got it) but it would be really great if dependencies could be forwarded in the useEffect function props and converted to a boolean declaring whether the dependency has changed (aka caused a re-render) or not.
Author   yamarco
🌐
Reddit
reddit.com › r/reactjs › should i use useeffect when its dependency is true/false and is directly from props?
r/reactjs on Reddit: Should I use useEffect when its dependency is true/false and is directly from props?
May 12, 2022 -

Can’t we just use the prop value directly instead of wrapping it in a useEffect?

Say,

Component = ({bool}) => {

If (bool) playSound()

return … }

Versus:

UseEffect(() => if(bool) playSound(), [bool])

These two cases have same behavior.

Update: It’s better to use useEffect, which only fires the side effect when the dependency changes when a component re-renders. It guards against incorrectly triggering the side effect if the dependency did not change value upon component re-render.

Discussions

reactjs - Change state conditioned on in useEffect without triggering the hook and without breaking the exhaustive dependencies rule - Stack Overflow
You can just deregister and while ... such that it doesn't depend on the same value. Just a working example of what I mean · You can also let me know what specific use case you are catering for such that I can help you more · import React, { useEffect, useCallback, useState ... More on stackoverflow.com
🌐 stackoverflow.com
November 6, 2019
reactjs - Is it okay to change boolean which is a hook and dependency of useEffect in React? - Stack Overflow
I am working on CSS Transition on React that it automatically unmount after 2 seconds. I am thinking about using useEffect and useState to solve this problem. I know that changing dependencies inside More on stackoverflow.com
🌐 stackoverflow.com
March 4, 2022
reactjs - How do we check the boolean value in useEffect in react hooks? - Stack Overflow
You can add another useEffect which watches this change, useEffect takes a second argument which is dependency array and the effect gets called if any of the dependency array value changes . More on stackoverflow.com
🌐 stackoverflow.com
August 27, 2021
reactjs - Better way to execute useEffect when boolean changes in one direction? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › rangeoshun › optimize-useeffect-by-using-the-condition-itself-as-a-dependency-1c2j
Optimize useEffect by using a condition as a dependency - DEV Community
April 3, 2020 - When you call useEffect, React checks your dependencies one-by-one. It has to, to be sure that your side effect takes place when any of the dependencies change. After this, your function runs and evaluates the condition it needs to.
🌐
Lightrun
lightrun.com › answers › facebook-react-feature-request---useeffect---provide-boolean-values-on-whether-dependency-has-changed
Feature Request - useEffect - Provide boolean values on whether dependency has changed.
There’s no need for this feature to be built into React itself. Everything can be done in userspace in a certain sense, however this issue shows that the current API of useEffect is somehow slightly off, as it mixes concepts of “dependencies” of the effect and “triggers” of the effect in the same parameter. Read more comments on GitHub > ... useEffect dependencies as dependencies: imho they are triggers, ... Feature Request - useEffect - Provide boolean ...
🌐
Stack Overflow
stackoverflow.com › questions › 71348141 › is-it-okay-to-change-boolean-which-is-a-hook-and-dependency-of-useeffect-in-reac
reactjs - Is it okay to change boolean which is a hook and dependency of useEffect in React? - Stack Overflow
March 4, 2022 - I am working on CSS Transition on React that it automatically unmount after 2 seconds. I am thinking about using useEffect and useState to solve this problem. I know that changing dependencies inside useEffect causes infinite loop. For example, the code below will cause infinite loop. const [count, setCount] = useState(0); useEffect(() => { setCount(prev => prev + 1); },[count]); But I think infinite loop won't happen if I set dependency to boolean and set if statement inside useEffect just like the code below.
Find elsewhere
🌐
Overreacted
overreacted.io › a-complete-guide-to-useeffect
A Complete Guide to useEffect — overreacted
March 9, 2019 - This article is a good primer on data fetching with useEffect. Make sure to read it to the end! It’s not as long as this one. [] means the effect doesn’t use any value that participates in React data flow, and is for that reason safe to apply once. It is also a common source of bugs when the value actually is used. You’ll need to learn a few strategies (primarily useReducer and useCallback) that can remove the need for a dependency ...
🌐
SheCodes
shecodes.io › athena › 228059-how-do-dependencies-work-in-useeffect
[React] - How do dependencies work in useEffect? - SheCodes | SheCodes
Understanding how dependencies work in the useEffect hook in React and how they control when the effect should run.
Top answer
1 of 2
1

You can add another useEffect which watches this change, useEffect takes a second argument which is dependency array and the effect gets called if any of the dependency array value changes .

In this case since you need to make a decision based on the nomStatus, you can add it as a dependency to your useEffect

useEffect(() => {
  if (nomStatus) {
    setShowCalender(true);
  }
}, [nomStatus]);
2 of 2
1

You can't since React state updates are asynchronously processed, the nomStatus state update won't be available until the next render cycle. Use the res.data[0].status value to set the showCalendar state.

const [nomStatus, setNomStatus] = useState(false);

useEffect(() => {
  const fetchData = async () => {
    const email = localStorage.getItem("loginEmail");
    try {
      const res = await Axios.get(
        "http://localhost:8000/service/activeStatus",
        {email}
      );
      setNomStatus(res.data[0].status);
      console.log("Get status data :" + res.data[0].status);
      if (res.data[0].status){
        setShowCalender(true);
      }
    } catch (e) {
      console.log(e);
    }
  };
  fetchData();
}, []);

Or you can use a second useEffect hook with a dependency on nomStatus state update to set the showCalendar state.

useEffect(() => {
  const fetchData = async () => {
    const email = localStorage.getItem("loginEmail");
    try {
      const res = await Axios.get(
        "http://localhost:8000/service/activeStatus",
        {email}
      );
      setNomStatus(res.data[0].status);
      console.log("Get status data :" + res.data[0].status);
    } catch (e) {
      console.log(e);
    }
  };
  fetchData();
}, []);

useEffect(() => {
  if (nomStatus){
    setShowCalender(true);
  }
}, [nomStatus]);
🌐
DEV Community
dev.to › hey_yogini › useeffect-dependency-array-and-object-comparison-45el
UseEffect dependency array and object comparison! - DEV Community
January 5, 2022 - This array will re-run useEffect, if the values inside it changes. This will work perfectly fine when the values passed in the dependency array are of type boolean, string or numbers.
🌐
Retool
retool.com › blog › hooks-and-state-102-the-dependency-array-in-useeffect
Retool Blog | Hooks and state 102: the Dependency array in useEffect()
July 9, 2025 - In the examples above, we have ... and booleans – into the dependency array. What about objects, arrays, and functions? These complex values pose a challenge because React uses referential equality to check whether these complex values have changed. In particular, React checks to see if the object in the current render points to the same object in the previous render. The objects have to be the exact same object in order for useEffect to skip running ...
🌐
Reddit
reddit.com › r/reactjs › useeffect conditional dependency arrays... but???
r/reactjs on Reddit: useEffect conditional dependency arrays... but???
April 1, 2022 -

Okay I read about this somewhere... I wish I could give credit where it's due.

But you build a conditional outside your useEffect... for cleanliness... and then put that in the useEffect dep array.

See attached image.

I am finding my useEffect runs regardless of the conditional... which maybe I need to state in the dependency array... conditional === true...

Dang as I type this... that is probably my problem. But I'll lean it here incase anybody else has not see something like this before.

https://www.instagram.com/p/Cb04lovOFOV/

Sorry for the instagram drop.. but apparently the reddit react doesn't let images to be uploaded. And I'm too lazy to open VS code and copy the code again. Sorry!

🌐
React
react.dev › reference › react › useEffect
useEffect – React
You can’t exclude shoppingCart from dependencies without breaking the reactivity rules. However, you can express that you don’t want a piece of code to “react” to changes even though it is called from inside an Effect. Declare an Effect Event with the useEffectEvent Hook, and move the code reading shoppingCart inside of it:
🌐
GitHub
github.com › facebook › react › issues › 18123
Discussion: useEffect hook with array dependency that has a default value causes render loop · Issue #18123 · facebook/react
February 25, 2020 - Default values for arrays (and objects) can be assigned within the destructuring of the props without causing re-renders (or even render loops) when the mentioned useEffect is not present (like, why should it trigger a re-render?). I'd expect react to behave the same in this case (don't compare empty arrays/objects by reference).
Author   gregor-mueller
🌐
Medium
neofish.medium.com › react-useeffect-usage-guide-59dd54f1b4a7
How to use React useEffect
January 5, 2022 - There are three types of values: boolean、 number and string. Such as true! == false, 1! == 2 and ‘1’! = = ‘2’. Shallow comparisons for reference types compare references to objects to memory addresses to which they point. There are types such as object, array and function. ... With an empty array of dependencies, equivalent to the Class component’s componentWillUnmount. Let us look at the react/index.d.ts#L902,count find useEffect callback function EffectCallback the return value of void | Destructor, the Destructor is optional Destructor.
🌐
React
react.wiki › home › react hooks › useeffect dependency array: deep mechanics explained
useEffect Dependency Array: Deep Mechanics Explained | react.wiki
January 1, 2026 - After each render, React compares the new dependency array with the previous one, element by element, using strict equality. ... function UserProfile({ userId }: { userId: number }) { const [user, setUser] = useState(null); useEffect(() => { fetchUser(userId).then(data => setUser(data)); }, [userId]); // ← Dependency array return <div>{user?.name}</div>; }
🌐
React
react.dev › learn › removing-effect-dependencies
Removing Effect Dependencies – React
Since roomId is a reactive value (it can change due to a re-render), the linter verifies that you’ve specified it as a dependency. If roomId receives a different value, React will re-synchronize your Effect. This ensures that the chat stays connected to the selected room and “reacts” to the dropdown: ... import { useState, useEffect } from 'react'; import { createConnection } from './chat.js'; const serverUrl = 'https://localhost:1234'; function ChatRoom({ roomId }) { useEffect(() => { const connection = createConnection(serverUrl, roomId); connection.connect(); return () => connection.d