Questions tagged [usecallback]

251 questions
0
votes
1 answer

Using react Hook, shows missing dependency in case of useCallback

I am learning the hooks in ReactJs and stuck to some kind of warnings like dependencies. Here in src/pages/home, I am using useCallback in it. And One more question, Could you please give me real life condition where I need to use useCallback and…
Rajat Sharma
  • 65
  • 1
  • 8
0
votes
1 answer

React hooks useCallback has dependency on function

I have below function const handleClick = React.useCallback( (value) => { dispatch({ value }); }, [dispatch] ); My question is, in my case, is it necessary to have useCallback ? how React determines if the dependency is changed…
peace and love
  • 239
  • 4
  • 13
0
votes
2 answers

React Hook useEffect has a missing dependency: 'execute'

I can't seem to find an answer to this despite trying different things. I keep getting the error: Line 18:5: React Hook useEffect has a missing dependency: 'execute'. Either include it or remove the dependency array …
Harsh Baid
  • 59
  • 8
0
votes
0 answers

React useCallback instead of useEffect for animation

Following along from a Scrimba tutorial on React Hooks, I've been trying to use, useEffect and useCallback for ways of preventing a component from re-rendering during requestAnimationFrame. I currently have the Playgroundcomponent that updates and…
James
  • 1,355
  • 3
  • 14
  • 38
0
votes
1 answer

Using React.memo and useCallback to prevent functions from causing re-renders

I am following this tutorial demonstrating react's 'useCallback' hook along with React.memo to prevent a function being render unnecessarily. To prove the concept we use useRef to console the number of renders. This worked with the function alone…
James
  • 1,355
  • 3
  • 14
  • 38
0
votes
1 answer

try to call a function object which uses a state variable that is changed inside useEffect, and get undefined state variable

Since my currentUser state variable is set in useEffect, and getJoinRoom requires currentUser so I set useCallback on getJoinRoom with dependency currentUser state, but it seems that currentUser is still not set when calling getJoinRoom Error on…
impressiveHen
  • 33
  • 1
  • 6
0
votes
1 answer

how to create a callbackRef with dependencies

This blog post and the official docs show how to use useCallback to create a callback ref. But neither one has an example of a case where useCallback has dependencies. How should I set that up? For example, if I do the following, it won't work,…
nbrustein
  • 727
  • 5
  • 16
0
votes
1 answer

What is the cache size of useCallback and useMemo react hook and why?

I'm looking at React source code and specifically at useCallback implementation. As far as I understand the cache size of useCallback is one. In mountCallback we initialize hook.memoizedState to an array where the first element is the callback - the…
Yos
  • 1,276
  • 1
  • 20
  • 40
-1
votes
1 answer

react native useCallback with dependency return null state on unMount

assume i have this code: const [value, setValue] = useState(); useEffect(() => { setvalue('1') return () => { clearData() } }, []); const clearData = useCallback(() => { console.log('data when unmount', value) }, [value]); But i…
famfamfam
  • 396
  • 3
  • 8
  • 31
-1
votes
1 answer

useCallback for function that incorporates batched redux actions (from HOC). What shall i put in the dependancy array?

I have this component import React from 'react'; import { batch } from 'react-redux'; const ContextMenu = ({ menuData, isOpen, changeIsMenuOpen, changeAssetType, }) => { return (
-2
votes
2 answers

Render only components with changes

I have an array with thousands of strings and is passed to a component: Main component: const array = ['name1', 'name2', 'name3']; const [names, setNames] = useState(array); const onClick = (index) => { setNames(names.map((name, i) => { if (i…
Henny Lee
  • 2,970
  • 3
  • 20
  • 37
1 2 3
16
17