Questions tagged [usecallback]
251 questions
2
votes
0 answers
React useEffect loop: circular dependency
I'm trying to call a function every time that function's parameters change and this has generated a loop that I don't know how to solve. I've tried implementing this in several ways, such as:
const [fromAmount, setFromAmount] = useState(1);
const…

n3n3
- 288
- 1
- 7
2
votes
1 answer
What useCallback is doing for the current component?
At react docs I've read
Pass an inline callback and an array of dependencies. useCallback will return a memoized version of the callback that only changes if one of the dependencies has changed. This is useful when passing callbacks to optimized…

Louay Al-osh
- 3,177
- 15
- 28
2
votes
1 answer
Accessing and updating canvas node callback inside of useEffect - React
I've created a canvas which is set to a state using a callback. circles are then created based on mouse x and y that are then drawn to the canvas state after clearing the canvas for each frame. each draw frame reduces the radius of the circles until…

Will Law
- 23
- 3
2
votes
2 answers
useRef and useEffect initial access and then later usage of useRef
How can I wait for ref to be ready but also only work inside my use effect with condition?
Here is what I want to do:
I want to select all rows in my DataGrid component using ref when popup is visible.
This code won't work, because I don't have ref…

Figen Güngör
- 12,169
- 14
- 66
- 108
2
votes
1 answer
Why does useIsMounted return a callback instead of the value itself?
I'm referring to useIsMounted from usehooks-ts. I'm trying to understand why the function is returning useCallback(() => isMounted.current, []) instead of just isMounted.current.
I've tested both ideas in a CodeSandbox that just uses a setTimeout to…

Vee
- 729
- 10
- 27
2
votes
1 answer
Should I remove all unecessary usage of usecallback and memo in a React app?
im working on a relatively large React codebase and I've seen that the previous developers used memo and usecallback liberally with the thought that by using these would improve performance. Obviously not, here is an example
export default function…

fardown
- 713
- 2
- 12
- 23
2
votes
1 answer
Wierd infinite loop with useEffect and useCallback
Ok then. I have this code and is just for practice so it could be a bit messy (please ignore the cammelCase convention or bad practices unless they are the cause of the problem, beacause I've already take note of it), howerver i'm going to describe…

Nahuel M.
- 146
- 8
2
votes
0 answers
A better way to reload() on click in React? Possibly with a useCallback hook?
After many infinite loops, I got the state to work and the page reloads on the click of my own refresh button.
I watched a few useMemo() and useCallback() tuts on Youtube but I haven't used the hooks enough to understand them.
I was able to get it…

Andi
- 31
- 3
2
votes
1 answer
How to use useCallback, useMemo and React.memo when dependency is an object?
I have useMemo when one of its dependencies is an Object that I get from the server, so even when the content of the object is the same - the useMemo is called over and over again in each sync from the server because the object itself is different…

user2993539
- 375
- 1
- 3
- 14
2
votes
0 answers
Too many useCallback, useEffect, useMemo.. is this what React hooks is supposed to be?
After using class components for some years, I embraced fully the new way of writing functional components and hooks. Instead of the deprecated componentWillReceiveProps where we compare a lot of props and write impossible to understand logic, we…

Paul Pacurar
- 145
- 12
2
votes
0 answers
Event listeners does not trigger in expo, react-navigation but use to work previously
For :
expo --version 4.9.0 and
"@react-navigation/bottom-tabs": "^5.11.11",
"@react-navigation/drawer": "^5.12.5",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
Event listeners never get triggered after an event…

gaurav
- 491
- 3
- 13
2
votes
1 answer
Children useCallback dependency hell
From what I understand you use useCallback to prevent rerendering so I've been using it in every function and my spider senses are telling me it already sounds bad.
But the story doesn't ends there, since I've been using it everywhere I'm now…

ne3zy
- 99
- 9
2
votes
3 answers
Dependencies in React useEffect cleanup function are not updated
I am facing a strange issue when trying to call a cleanup function on component unmount with useEffect.
In my useEffect return I call a useCallback function where the dependencies are added correctly. In there a check the state variable called…

Elisa M.
- 51
- 5
2
votes
2 answers
state update not happening in useEffect with api call
I'm new to React.js. I want to update options in my form based on some other state.I'm calling an api to fetch the new options. So this api needs to be called whenever state change happens.
const [selectedNamespace,setselectedNamespace] =…

Vrinda Agarwal
- 23
- 4
2
votes
1 answer
React Lifecycles managing intervals with changing values
In one of my components I have a useEffect setup where an interval is set to fetch a function.
It's basically set up as follows:
...
const token = useToken() // custom hook that updates whenever access_token updates
const fetchData =…

Barry Michael Doyle
- 9,333
- 30
- 83
- 143