Questions tagged [react-usecallback]

57 questions
0
votes
1 answer

React usecallback not honoring dependency change caused by child function

Hopefully someone can help me with this, I will be quite grateful. I searched though previously answered questions and I can't find something exactly quite like this. In a nutshell: I have a useCallback react hook which renders a set of buttons.…
0
votes
1 answer

How to clean up event listener inside useCallback

const ref = useCallback((node) => { if (node) { // ...intersection observer code goes here } }, []); return
I use useCallback hook to setup intersection observer listener once ref's node is available. My question is what is…
sdvnksv
  • 9,350
  • 18
  • 56
  • 108
0
votes
1 answer

How to use a utility class instance in react different components and prevent reinitialization and only one instance is used on all components

I have a class in a separate file and two or more different react components that need to use the class methods One approach was I initially created an instance of the class outside the react components to prevent re rendering and having…
0
votes
1 answer

State is not updated properly when using React.memo and useCallback

My problem is quite common but it is not easy to figure out what is wrong with my example. I have nested components Parent->Child1->Child2. State and setState are passed in props to child components. I want to avoid re-renders in child components…
WhatIsHTML
  • 548
  • 1
  • 7
  • 19
0
votes
2 answers

Im getting invalid hook call error with useCallBack in React

im getting invalid hook call error in my project.
0
votes
2 answers

Time limit to consider as computationally expensive for using useMemo/useCallback

According to dozens of articles, including React docs, using useCallback and useMemo hooks helps prevent unnecessary re-renders. On the other hand, these performance-optimizing hooks are not free and come at a cost. And their benefit might not…
0
votes
1 answer

How to properly fix React Hook useCallback has a missing dependency

I updated my Eslint rules using airbnb in my React typescript project. I get those errors now: React Hook useCallback has a missing dependency: 'setCookie'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps I have…
meez
  • 3,783
  • 5
  • 37
  • 91
0
votes
1 answer

Wrap function in useCallback

In the code snippet below, I'd like to move this function out of jsx and wrap into useCallback. {suggestedTags.length ? (
{suggestedTags.map((tag) => { return (
Paul
  • 53
  • 3
  • 21
0
votes
1 answer

React functional component re-rendering infinitely when using Axios in useCallback hook?

Here is a file uploading component, everything works at expected, however, when attempting to POST the file using Axios in a useCallback, the ProgressBar component re-renders infinitely if there is an error from Axios. If I comment out the Axios…
zewicz
  • 125
  • 9
0
votes
1 answer

Why is the useEffect changes to state in the Parent not happening in the Child?

Below is a FileUploader Component (parent) that renders ProgressBar's (children) as a file is added. I intend to pass in the FileReader onprogress so that the width of the progress bar goes from 0 to 100. To test I made a useEffect counter that goes…
0
votes
1 answer

Access to updated context inside memoized function

I created a component (for websocket communication, as a react context) that needs to access to my AppContext component. The WebSocketContext component makes use of useCallback and useMemo, so that the websocket connection is not alway re-created on…
0
votes
1 answer

React: create closure that's referntially equal across renders with useCallback

I need to create an event handler in React in a custom hook and I'd like the event handling function to be referentially equal across renders for ..reasons (yes I do see how I can do this w/o but I want to understand). Can I use useCallback as…
Peter Gerdes
  • 2,288
  • 1
  • 20
  • 28
0
votes
0 answers

UseCallback still triggering infinitely, What should I do?

My code is: const Chat = () => { const { type,title,roomId } = useParams(); const [roomDetails, setRoomDetails] = useState(null); const [roomMessages, setRoomMessages] = useState([]); const getConversation = useCallback(() => { …
0
votes
1 answer

React.useCallback : it doesn't prevent continuos re-rendering

I'm trying to use React.useCallback functions within React.useEffect in order to avoid continuous re-rendering. My objective is, once selected a sorting option, keep the list sorted even when new elements are added. But without…
Raphael10
  • 2,508
  • 7
  • 22
  • 50
0
votes
1 answer

React Native useCallback state not updating

I am currently trying to implement useCallback for a function which updates an existing state array by adding a new object. const [objects, setObjects] = useState([]); useEffect(() => { dropApiService.GetObjects(drop.id).then(result => { …
Duncan Palmer
  • 2,865
  • 11
  • 63
  • 91