Questions tagged [usecallback]
251 questions
1
vote
2 answers
UseEffect throwing Warning for useState
Hello Guys I am getting this warning
React Hook useEffect has missing dependencies: 'financialBackground'
and 'setFinancialBackground'. Either include them or remove the
dependency array. If 'setFinancialBackground' changes too often, find
the…

Tahmass Raheem
- 27
- 1
- 7
1
vote
0 answers
Should I use an updater function and const in a useCallBack or a let variable?
Both of the following work and the child component doesn't rerender, but which one is preferable and why?
This one using a const and an updater function
const [count, setCount] = useState(0)
const increment = useCallback(() => {
setCount(c => c…

Squirrl
- 4,909
- 9
- 47
- 85
1
vote
2 answers
Problem with rendering object prop sent to child component
The problem is: Every time I click the button, I see "Button render" in the console. But I want to see this post only once
The problem is: Every time I click the button, I see "Button render" in the console. But I want to see this post only…

Mümin ZEHİR
- 74
- 1
- 7
1
vote
1 answer
useCallback with updated state object - React.js
I have a POST API call that I make on a button click. We have one large state object that gets sent as body for a POST call. This state object keeps getting updated based on different user interactions on the page.
function QuotePreview(props) {
…

Thomas Sebastian
- 1,582
- 5
- 18
- 38
1
vote
1 answer
The dependency array of useEffect, useCallback, useMemo
I'm so confused of the dependency of React Hooks.
Here's the example:
const memorizeValue = useMemo(() => {
return {
count,
setCount,
}
}, [count, setCount])
In React documentary:
Note
The array of dependencies is not passed…

Baiwei
- 235
- 2
- 7
1
vote
1 answer
useCallback with state dependency causes infinite loop
I’ve got a useCallback that updates state, but because it requires that state as a dependency, it creates an infinite loop when it updates the state. I’m using useImmer here, but it happens when using plain useState, too.
const [panels,…

Brandon Durham
- 7,096
- 13
- 64
- 101
1
vote
0 answers
callback with angular error handler is not working - attached the example code
I have two classes in angular and typescript. One class CustomErrorHandlerService is inherting from angular error handler which provides an callback and the other class ErrorProessor is processing that error by using the callback. The problem is…

Naren
- 139
- 1
- 17
1
vote
1 answer
Do I get any performance gain from useCallback when the function is used as a private method?
React's useCallback hook offers a performance gain when passing the generated (memoized) function to a child component in order to avoid unnecessary re-renders.
Do I get any performance gain when the hook is used as internal ("private")…

antoniom
- 3,143
- 1
- 37
- 53
1
vote
1 answer
React Hook useEffect/useCallback has a missing dependency
I have this warning in my ProductUpdate.js file.
My code looks like this:
const fetchProduct = () => {
getProduct(slug)
.then(p => setValues({...values, ...p.data }))
}
useEffect(() => {
fetchProduct()
…

Rokus
- 21
- 5
1
vote
1 answer
Is this incorrect use of useCallback and useMemo?
When should we worry about functional components redefining variables and functions??
I think this first case is clearly unnecessary, functions is not expensive to create(and the react dev tools profile test didn't detect performace change with…

pavaj93490
- 81
- 1
- 5
1
vote
1 answer
how can I access the latest state outside of the setState callback?
Because of the asynchronous nature of React setState and the newly introduced react concurrent mode after a lot of research, I don't know how I can access the guaranteed latest state in the following scenario or any other scenario.
An answer from a…

Abbas Hosseini
- 1,545
- 8
- 21
1
vote
1 answer
how to use useEffect and useCallback, so the screen don't call the function before button clicks
I'm learning useEffect and useCallBack hooks. What I'm trying to do is add a function in the useCallBack, and make sure that the screen will not call this function until I click on a button. Here is my sample code below. Currently, it calls the…

Yuze Sun
- 63
- 1
- 6
1
vote
2 answers
I don't understand useCallback
I need to change the checkbox checked status, but useCallback re-renders component a lot of times. I don't understand how it works. I've read a lot of materials about it.
const AppealsList = () => {
const [isFiltered, setFiltered] =…

MuffinColor
- 21
- 1
- 5
1
vote
2 answers
How to include missing dependency in useEffect but prevent infinite loop execution of function?
I'm working on a fairly simple React functional component that gets a value (tag) from the URL and requests documents from firestore correspondig to that tag (inlc. firestore query cursor to use with a load more button). The whole component consists…

Ralph
- 35
- 1
- 8
1
vote
1 answer
useCallback in list item component instead of in parent
I created a react app, in which I have a list of items with delete action.
I know that if i pass this delete action from parent (the items container) , i can use "useCallback" in the parent to prevent unneeded recreations of the delete method.
But,…

eyal gromzin
- 155
- 2
- 11