The reason for the experienced behavior is not that useEffect isn't working. It's because of the way function components work.

If you look at your child component, if useEffect is executed and the component rerenders, defaultValues would be set to 0 again, because the code inside of the function is executed on each render cycle.

To work around that, you would need to use the useState to keep your local state consistent across renders.

This would look something like this:

function EditKat({ aa }) {
  // Data stored in useState is kept across render cycles
  let [defaultValues, setDefaultValues] = useState(0)

  useEffect(() => {
    setDefaultValues(2) // setDefaultValues will trigger a re-render
  }, [aa])

  console.log(defaultValues)
}
Answer from Linschlager on Stack Overflow
🌐
GitHub
github.com › tannerlinsley › react-query › issues › 2628
Bug: useEffect not triggering on [deps] change · Issue #2628 · TanStack/query
September 2, 2021 - In card-status.js I registered useEffect which is watching for certain changes and it just displays the message whenever [deps] change. The problem is that one state change gets swallowed by useEffect. It can be seen if you click on a button and watch the console, useEffect is not triggered even though UI updates correctly aka rerender is triggered.
Author   Tosheen
Discussions

My useEffect in Context.js is not triggering at all. I am trying update state within it
Can you show an example of how you’re using the context? More on reddit.com
🌐 r/reactjs
7
4
September 8, 2022
Bug: useEffect not firing when depending on hook value
React version: 18.2.0 Steps To Reproduce Setup a hook which returns a ref.current value. Setup a useEffect which depends on hooks return value. Have some useState which causes re-renders. The useEf... More on github.com
🌐 github.com
2
August 21, 2023
React useEffect doesn't trigger sometimes when I update my list as its dependency
This is part of my code. useEffect doesn't trigger when I append a new element to mylist, but it does when I delete an element. More on stackoverflow.com
🌐 stackoverflow.com
January 4, 2020
How to fix the issue of UseEffect not triggering on route change even after feeding in Params Object's property as dependency?
Technically getUser and getUserRepos should be part of your dependency array. More on reddit.com
🌐 r/reactjs
17
2
September 23, 2022
🌐
DhiWise
dhiwise.com › post › how-to-fix-useeffect-not-triggering-in-your-react-project
Reasons Why UseEffect Is Not Triggering In Your React App
May 29, 2024 - It’s essential to understand that useEffect runs after every render by default, but if you provide a dependency array, it will only run when the specified props or state variables change. Additionally, the data flow from parent to child components can impact the triggering of useEffect, making it crucial to keep the data flow predictable and avoid complexities that make it difficult to understand and debug.
🌐
Reddit
reddit.com › r/reactjs › my useeffect in context.js is not triggering at all. i am trying update state within it
r/reactjs on Reddit: My useEffect in Context.js is not triggering at all. I am trying update state within it
September 8, 2022 -

I am trying to setState inside useEffect but the useEffect is not getting triggered at all

import React, { useEffect, useState } from 'react'

import items from './data'


const RoomContext = React.createContext();



const RoomProvider = ({children}) => {
   
    const [state, setState] = useState({
        rooms: [],
        sortedRooms: [],
        featuredRooms: [],
        loading: true,
    })


    const formatData =(items) => {

        let tempItems = items.map((item)=> {
            let id = item.sys.id;
            let images = item.fields.images.map(image => image.fields.file.url);
        
            let room= {...item.fields, images,id};

            return room;
        
        });

        return tempItems;


    }

  
    useEffect(()=> {
        
        console.log(items)
        let rooms= formatData(items);
        console.log(rooms)
        let featuredRooms = rooms.filter(room => room.featured === true)
        console.log("aaaaaaa",featuredRooms)
        
        setState({
            rooms,
            sortedRooms: rooms, 
            featuredRooms,
            loading: false
        })
        
        console.log("render")
    },[state])

    
  console.log("dying")

  return (
    <RoomContext.Provider value={{state,setState}}>
    
        {children}
    
    </RoomContext.Provider>
  )
}

const RoomConsumer = RoomContext.Consumer;

export { RoomContext, RoomProvider, RoomConsumer };
🌐
React
react.dev › reference › react › useEffect
useEffect – React
If your Effect wasn’t caused by an interaction (like a click), React will generally let the browser paint the updated screen first before running your Effect. If your Effect is doing something visual (for example, positioning a tooltip), and the delay is noticeable (for example, it flickers), replace useEffect with useLayoutEffect.
🌐
GitHub
github.com › facebook › react › issues › 27256
Bug: useEffect not firing when depending on hook value · Issue #27256 · facebook/react
August 21, 2023 - Link to code example: https://codesandbox.io/s/zealous-jasper-fvynsw?file=/src/App.js ... import React, { useRef, useEffect, useState } from "react"; export default function App() { const hooksValue = useHookThatReturnsRefValue(); console.info("Render:", hooksValue); useEffect(() => { console.info("useEffect ran!
Author   ThomasMorrison
🌐
Reddit
reddit.com › r/reactjs › how to fix the issue of useeffect not triggering on route change even after feeding in params object's property as dependency?
r/reactjs on Reddit: How to fix the issue of UseEffect not triggering on route change even after feeding in Params Object's property as dependency?
September 23, 2022 -

Here's my App.js component

App.js

function App() {
  return (
    <GithubProvider>
      <AlertProvider>
        <Router>
          <div className="flex flex-col justify-between h-screen">

            <Navbar />

              <main className='container mx-auto px-3 pb-12'>
                <Alert />

                <Routes>
                <Route path="/" element={<Home />} />

                <Route path="/about" element={<About />} />
                <Route path="/user/:login" element={<User />} /> {/* ISSUE */}

                <Route path="*" element={<NotFound />} />

              </Routes>


              </main>

            <Footer />

          </div>
        </Router>
      </AlertProvider>
    </GithubProvider>
   
  );
}

The route change to the user component happens in Home Component, I search for a github profile,
a lift of profiles are displayed, I click on the visit profile button on the profile card, which Links me to User component

UserItem.js:

import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'


const UserItem = ({user: {login, avatar_url}}) => {

    return (
        <div className='card shadow-md compact side bg-base-600'>
        <div className='flex-row items-center space-x-4 card-body'>
          <div>
            <div className='avatar'>
              <div className='rounded-full shadow w-14 h-14'>
                <img src={avatar_url} alt='Profile' />
              </div>
            </div>
          </div>
          <div>
            <h2 className='card-title'>{login}</h2>
            <Link
              className='text-base-content text-opacity-60'
              to={`/user/${login}`}
            >
              Visit Profile {/* TRIGGERING HERE!!!!!!!!!!! */}
            </Link>
          </div>
        </div>
      </div>
    )
}


UserItem.propTypes = {
    user: PropTypes.object.isRequired,
}

export default UserItem;

My user Component where the function getUser needs to be triggered->
The function getUsers works fine as when i used it outside an useEffect, it did give me the right response from the fetch call inside.

User.js

import React, { useEffect, useContext } from 'react'
import {FaCodepen, FaStore, FaUserFriends, FaUsers} from 'react-icons/fa'
import { Link } from 'react-router-dom'
import GithubContext from '../context/github/GithubContext'
import { useParams } from 'react-router-dom'
import Spinner from '../components/layout/Spinner'
import RepoList from '../components/repos/RepoList'





export const User = () => {

    const params = useParams()
    
    
    const { getUser, user, loading, getUserRepos, repos } =
    useContext(GithubContext)
    
    console.log("params", params, "login", params.login) // WORKS FINE
    
    
    useEffect ( () => {
        console.log("use-effect", getUser, "", params.login)
        getUser(params.login)
        getUserRepos(params.login)

    },[params.login]) // DOESNT TRIGGER WITH [] or [params.login]

    console.log( "user-check",user) // user object empty
    
    const {
        name,
        type,
        avatar_url,
        location,
        bio,
        blog,
        twitter_username,
        login,
        html_url,
        followers,
        following,
        public_repos,
        public_gists,
        hireable,
      } = user


      console.log("YES THIS PAGE") // Here I was checking whether page is being mounted and YES it is being mounted 


    const websiteUrl = blog?.startsWith('http') ? blog : 'https://' + blog


    if(loading){
        return <Spinner />
    }



  return (<> TYPICAL INFORMATION DISPLAY UI </>)
}
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › most-common-react-useeffect-problems-and-how-to-fix-them
React.useEffect Hook – Common Problems and How to Fix Them
October 14, 2021 - Nice! Everything looks and works as expected. But wait... what is this? ... React Hook useEffect has a missing dependency: 'user'. Either include it or remove the dependency array.
🌐
DEV Community
dev.to › hnrq › useupdateeffect-useeffect-that-doesn-t-run-on-mount-8l6
useUpdateEffect: useEffect that doesn't trigger on mount - DEV Community
January 20, 2021 - const useUpdateEffect: typeof useEffect = (effect, deps) => { const isFirstMount = useRef(true); useEffect(() => { if (!isFirstMount.current) effect(); else isFirstMount.current = false; }, deps); }; Some of you may be asking: "Why useRef?". Well, because it persists its value across renders and doesn't trigger a re-render.
🌐
Reddit
reddit.com › r/react › function specified in useeffect hook doesn't run
r/react on Reddit: Function specified in useEffect hook doesn't run
October 14, 2021 -

Hello,

I have a functional object which has three variables managed by the useState hook. These are categories, activeCategories and shownGames. For now I need something simple - run a function when categories update. I am using useEffect hook but it doesn't seem to work.

This is the code for the needed parts - https://pastie.io/uyakqz.js

I use JSON.stringify to check for the category updates (found that solution on StackOverflow). The issue is that the function specified in the useEffect hook doesn't run (it only runs when I load my page). Any help is appreciated!

🌐
KnowledgeHut
knowledgehut.com › home › blog › software development › how to use useeffect in react js: a beginner-friendly guide
React useEffect() Hook: Structure, Usage, Examples & Tips
July 22, 2025 - This is especially useful for storing previous values, timers, or DOM nodes. Inside useEffect, useRef can be used to avoid stale closures by constantly referencing the latest value. Unlike useState, updating a ref doesn’t trigger a component update, which makes it more efficient for tracking values that don’t affect rendering.
🌐
DEV Community
dev.to › trunghieu99tt › you-don-t-know-useeffect-4j9h
You don't know useEffect - DEV Community
August 21, 2021 - Case 2: Objects have different values, but their references are the same (this case happens when you partially update the object but don't trigger a re-new action). Each of the above 2 cases will affect our useEffect which leads to unexpected behavior.
🌐
Reddit
reddit.com › r/reactjs › do useeffects run if the component state doesn't change regardless of the dependencies they have been provided with?
r/reactjs on Reddit: Do useEffects run if the component state doesn't change regardless of the dependencies they have been provided with?
February 18, 2023 -

So I have this code:

import { useEffect, useState } from "react";

function useCounter(arr = [1, 2, 3, 4, 5]) {
    console.log("useCounter");
    const [counter, setCount] = useState(0);
    useEffect(() => {
        console.log("Effect");
        for (const i of arr) {
            setCount(i);
            console.log(counter);
        }
    }, [arr]);
}

function App() {
    console.log("____________________________________");
    useCounter();
    console.log("App");
    return <div className="App" />;
}

export default App;

It outputs this:

____________________________________
useCounter
App
Effect
0 (5 times)
____________________________________
useCounter
App
Effect
5 (5 times)
____________________________________
useCounter
App

Stuff going on with the first 2 rerenders is pretty straightforward and explainable (if not I will write it in a comment or edit this post writing my interpretation of what's going on) but what I couldn't wrap my head around is what's going on on the 3rd rerender.

So "useCounter" is getting logged because useCounter hook is being called then App is logged because it goes next (useEffect's callback is getting called right after the component renders something, so in this case it goes at the end), but useEffect's callback is not getting called even tho it's dependency (arr) was reestablished when useCounter was called and arr argument was assigned with a new instance of array [1,2,3,4,5] so it's a new array which is passed as a dependency to useEffect so it should run again right? causing an infinite loop of rerenders, but it doesn't, why is that happening? I have a guess that it somehow realizes that the previous counter and current counter gonna end up the same so no state changes and thus there is no point running useEffect's callback anymore despite dependency change but how is that happening without running the callback?

That question doesn't make me rest maybe react community could help me, please bring me peace at last

Top answer
1 of 5
3
[upd] I did not noticed that up to console.log useEffect is not called on 3rd re-render. Everything below still is valid, but has nothing to do with exact question "but why effect does not run at 3rd run?" each time component rerenders, useEffect strictly(think about it as ===, while actually, I believe, it's Object.is but in your case it does not matter) compares every dependency to previous value. Since argument arr is not passed to your hook, default value is used. Since default value defined inline, it's different each time. So on every rerender effect runs. To illustrate: function test(a = [1, 2]) { return a; } test() === test() // false or even easier: [1,2] === [1,2] // false
2 of 5
2
I got curious, so I tried to find out what was causing this. From the useState docs : If the new value you provide is identical to the current state, as determined by an Object.is comparison, React will skip re-rendering the component and its children. This is an optimization. Although in some cases React may still need to call your component before skipping the children, it shouldn’t affect your code. That last part seems to be what you're hitting. It seems concurrent mode does something but bails out of the render since the state is the same or something. I don't know why it needs to do it though. I also tried to add a child, and like the useEffect, it doesn't call it either. The behavior your seeing is exactly as described in the docs. Since you set the state to 5 two times, the second time it won't do an actual re-render. I'm also curios how you managed to code yourself into this, and got to the conclusion that react is the weird one.
🌐
Dave Ceddia
daveceddia.com › useeffect-hook-examples
How the useEffect Hook Works (with Examples)
October 22, 2020 - So, even though we’re passing [inputRef] as the 2nd argument of useEffect, it will effectively only run once, on initial mount. This is basically “componentDidMount” (except the timing of it, which we’ll talk about later). To prove it, try out the example. Notice how it focuses (it’s a little buggy with the CodeSandbox editor, but try clicking the refresh button in the “browser” on the right). Then try typing in the box. Each character triggers a re-render, but if you look at the console, you’ll see that “render” is only printed once.
🌐
Dmitri Pavlutin
dmitripavlutin.com › react-useeffect-infinite-loop
How to Solve the Infinite Loop of React.useEffect()
February 26, 2023 - The reference change doesn't trigger re-rendering. Check out the demo. Now, as soon as you type into the input field, the countRef reference is updated without triggering a re-rendering — efficiently solving the infinite loop problem. Even if you set up correctly the useEffect() dependencies, still, you have to be careful when using objects as dependencies.
🌐
Linguine Code
linguinecode.com › home › blog › react useeffect hook with code examples
React useEffect hook with code examples
July 16, 2020 - The second console message should ... gets triggered. If we take a look at the console log again, we can see the order of the lifecycles that it went through. ... This is the normal behavior that you would see in a traditional React class component. By running an empty array [] as a second argument, you’re letting React know that your useEffect function doesn’t depend ...
🌐
Jkettmann
jkettmann.com › dont-useeffect-as-callback
Don't useEffect as callback!
April 11, 2020 - It doesn't cause an error, but it causes unnecessary re-renders and code complexity. We'll see two examples where useEffect is basically a callback and how you can simplify code like that. This is a simple example component where a state update is supposed to trigger a callback.