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
🌐
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.

🌐
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
Discussions

reactjs - Change state conditioned on in useEffect without triggering the hook and without breaking the exhaustive dependencies rule - Stack Overflow
Thus, I have a boolean variable in state to keep track of whether the mutation has already been registered and I register conditionally based on it. Right after I register the mutation in the useEffect, I set this variable to true. Consequently, I set it to false in my deregister mutation function right after I conduct the deregistration. Here comes the issue: In order to adhere to the exhaustive dependency ... 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
0 Change state conditioned on in useEffect without triggering the hook and without breaking the exhaustive dependencies rule · 3 Better way to execute useEffect when boolean changes in one direction? More on stackoverflow.com
🌐 stackoverflow.com
March 4, 2022
useEffect conditional dependency arrays... but???
useEffect runs every time the variables specified in the dependency array change, regardless of their value. If you want to run logic conditionally, you'll need to have an if statement in the effect function and include all variables in the dependency array instead. More on reddit.com
🌐 r/reactjs
12
3
April 1, 2022
Discussion: useEffect hook with array dependency that has a default value causes render loop
So maybe this is not a bug (because it's default JavaScript behavior) but a pitfall that should be documented in the useEffect-section of the hooks documentation. I'm not quite sure because it feel... More on github.com
🌐 github.com
13
February 25, 2020
🌐
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 - You cannot conditionally call useEffect or any other hook for that matter. In these cases, you add the condition in the function performing the side effect itself, while the variables checked in the condition go into the dependency array.
🌐
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.
The concepts of “dependency” and “effect trigger” are not the same and thus should probably not share the same argument. ... This can be done in userspace. 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.
🌐
Overreacted
overreacted.io › a-complete-guide-to-useeffect
A Complete Guide to useEffect — overreacted
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.
Find elsewhere
🌐
LogRocket
blog.logrocket.com › home › how to use the useeffect hook in react: a complete guide
How to use the useEffect hook in React: A complete guide - LogRocket Blog
June 3, 2025 - In this case, “conditions” mean one or more dependencies have changed since the last render cycle. The signature of the useEffect Hook looks like this:
🌐
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.
🌐
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 - 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.
🌐
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!

🌐
Medium
medium.com › suyeonme › react-lets-deep-dive-into-deps-array-of-useeffect-13ab96468db7
React: Let’s deep dive into deps array of useEffect | by Suyeon Kang | suyeonme | Medium
July 31, 2022 - If we want to run useEffect based on the object(reference type), we should compare dependencies with deep equal.
🌐
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.
🌐
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 code above, the code inside useEffect will only be rerun if the url prop changes. Callout: The behaviors without the dependency array and with an empty [] dependency array are very different:
🌐
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
🌐
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:
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]);