usecallback Questions

3

Solved

Why is an infinite loop created when I pass a function expression into the useEffect dependency array? The function expression does not alter the component state, it only references it. // componen...
Mossman asked 26/6, 2020 at 19:21

3

So as i understand the difference between the two is that useCallback is used if a function or object or array is returned while useMemo when a primitive is returned. But i was looking up debouncin...
Brummell asked 20/1, 2022 at 16:37

3

Solved

Consider this example: let memoizedCb = React.useCallback( memoize((param) => () => someFunction(param)), [] ); where memoize is from external library like "fast-memoize". Abov...
Narcoanalysis asked 3/11, 2021 at 19:4

3

Solved

Outside of the counter example seen in many YouTube tutorial videos, what are practical/real-world use cases for useMemo and useCallback? Also, I've only seen an input focus example for the useRef ...
Spencer asked 1/3, 2021 at 20:29

2

Solved

As far as I've known, functions that defined in a React's functional component are regenerated whenever the component rerenders. Since useCallback can be triggered by specific dependencies, it prev...
Sanctify asked 23/7, 2019 at 4:10

1

Solved

I have few scenarios and I'd like to understand the differences in regards to rendering and performance. The example shown below is for a simple function but please consider a more complex one too ...
Vada asked 7/9, 2021 at 15:20

2

Solved

I am recently refactoring a web app using React Hooks. I encounter a problem regarding useCallback. Based on description of Kent: https://kentcdodds.com/blog/usememo-and-usecallback, useCallback is...
Ciborium asked 30/10, 2019 at 6:48

1

Solved

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 pr...
Testee asked 6/3, 2021 at 20:35

2

From what i understood from React documentation and other material across web, useCallback is used to avoid re-rendering of child component by ensuring that memoized version of callback is passed t...
Candicecandid asked 9/1, 2020 at 11:52

2

Solved

I have a component that uses event listeners in several places through addEventListener and removeEventListener. It's not sufficient to use component methods like onMouseMove because I need to dete...

1

Solved

In my react app, I am rendering different instances of <Item> Components and I want them to register/unregister in a Context depending if they are currently mounted or not. I am doing this wi...

1

This is very likely a dumb question -- I have the understanding that anything that triggers a side-effect should be handled with useEffect. I was wondering if that understanding is correct. Particu...
Insidious asked 10/8, 2020 at 1:36

1

Solved

I'm trying to use Typescript and useCallback, but I'm having this error Expected 0 arguments, but got 1 This is my code const searchFriends = useCallback(() => (filterValue: string): void =...
Photodrama asked 28/5, 2020 at 9:22

1

Solved

I can not fulfill all the conditions: I need some function inside useCallback, because I set it as props to child component (for re-render preventing) I need to use debounce, because my function ...
Cohberg asked 19/5, 2020 at 8:49

1

Solved

My Callback returning same state after calling it again and again i am new to react hooks in react classes i could have used shouldcomponentupdate and could have solved this issue but there isn'...
Flexure asked 10/5, 2020 at 9:8

1

Solved

I have a few components that all call the same function on an onPress handler, let's say it looks like the following: function MyComponent () { const dispatch = useDispatch() const updateThing ...
Willemstad asked 8/5, 2020 at 12:56

1

Solved

I'm trying to use React hooks for memoizing a callback. This callback specifically uses a function that's defined on an object. const setValue = useCallback((value) => { field.setValue(key, val...
Paisley asked 22/11, 2019 at 4:34

2

Solved

I'm trying to challenge myself to convert my course project that uses hooks into the same project but without having to use hooks in order to learn more about how to do things with class components...
Merridie asked 21/2, 2020 at 18:22

2

Solved

I have a mystery. Consider the following custom React hook that fetches data by time period and stores the results in a Map: export function useDataByPeriod(dateRanges: PeriodFilter[]) { const is...
Gent asked 5/1, 2020 at 5:50

2

Solved

I have the counter component. I encapsulated the business logic with custom hook. Should I optimize functions by means useCallback? If there is input onchange handler, will the situation be the sam...
Odilia asked 21/11, 2019 at 12:35

1

Solved

I've build an custom custom post hook that returns the API response and the API post. And I am using useCallback hook to set the Response state Where it goes wrong is that the Package prop doesn't...
Outrider asked 8/11, 2019 at 20:19

2

I'd like to start a discussion on the recommended approach for creating callbacks that take in a parameter from a component created inside a loop. For example, if I'm populating a list of items tha...
Ceballos asked 26/8, 2019 at 18:22

2

Solved

When passing callback to component, I should use useCallback hook to return a memoized callback (to prevent unneeded renders): import doSomething from "./doSomething"; const FrequentlyRerenders = ...
Gonidium asked 3/5, 2019 at 5:48
1

© 2022 - 2025 — McMap. All rights reserved.