Questions tagged [usecallback]
251 questions
0
votes
1 answer
How to add Event Listeners to UseRefs within UseEffect
I want to add an eventListener to a node in my React component. I am selecting the node with a useRef hook. I am useCallback since the useRef is null on it's first render.
const offeringsContainer = useRef(null);
const setOfferingsContainer =…

Isaac Medina
- 332
- 1
- 5
- 17
0
votes
1 answer
How to sto React useEffect hook from rendering duplicated data
I have a component where I use useEffect and inside call a function fetchLatest(). fetchLatest() is an action that makes a network request to get all movies that have been released during the current year. I am using Redux and in my store I have a…

Michael Torres
- 512
- 3
- 21
0
votes
1 answer
ReactJS Hooks. TypeError: Object(...) is not a function
I am new to reactJS, I am trying to develop a weather app using React Hooks. The useEffect hook runs infinitely, even the dependency is the same as before. So I decide to use useCallBack hook, However it shows an error.
Code as below:
import…

Leo Li
- 15
- 5
0
votes
2 answers
React Hook useEffect missing deps
I am using a useEffect hook and am getting a compiler error saying React Hook useEffect has missing dependencies. Either include them or remove the dependency array react-hooks/exhaustive-deps
It says this for both functions. I was wondering how…

PetullaPapi
- 41
- 1
- 5
0
votes
1 answer
Best way to resolve react-hooks/exhaustive-deps
Here is my error: "The 'setPartData' function makes the dependencies of useEffect Hook (at line 44) change on every render. Move it inside the useEffect callback. Alternatively, wrap the 'setPartData' definition into its own useCallback()…

N8BIZ
- 151
- 1
- 14
0
votes
1 answer
React - useCallback throwing error on renderProps function
I'm passing renderProps function in the props. i want to wrap it with useCallback, so the optimised child component will no re-render on the function creation.
when wrapping the function with useCallback i get this error:
Invalid hook call. Hooks…

Itay Tur
- 683
- 1
- 15
- 40
0
votes
1 answer
Getting a Typescript error with useCallback() in Visual Studio Code
I'm new to React hooks, and have run across this code:
const multiply = useCallback((value: number) => value * multiplier, [multiplier]);
(from https://medium.com/@jrwebdev/react-hooks-in-typescript-88fce7001d0d)
This is confusing to me and Visual…

Scott Schafer
- 487
- 3
- 14
0
votes
0 answers
In the react timer application component is not re-rendering
Can somebody spot the bug, UI is not rendering, I tried by passing formatTime as a dependency to the useEffect but it is behaving very annoyingly.
Observation: It's inconsistent sometimes it works on page reload but sometimes it don't rerender the…

Abhin Pai
- 332
- 3
- 10
0
votes
0 answers
Are redux store values up-to-date in the React.callback method that just updated them?
If I call a useCallback method to update a redux store value that is in its dependency array, will I get the updated value immediately or on the next call of the method?
For example, if the value in this example is 5 when I call the method, will I…

Ryan Pergent
- 4,432
- 3
- 36
- 78
0
votes
1 answer
does `useCallback` have something like a `useRef.current` inside it that will ensure that calls always use the latest version of the callback?
I have a situation where I am loading several datasets; the user can choose how many to load. All the datasets are rendered on the same chart. The datasets load individually and asynchronously.
The code is something along the lines of
export const…

jnnnnn
- 3,889
- 32
- 37
0
votes
1 answer
App freezes when trying to pass a function in SetParams React-Native
I am trying to use setParams to pass a function to handle a button click in my navigationOptions but my app freezes instead. Here is my code and any help would be greatly appreciated. Thanks
const handleVisibility = useCallback(()=>{
…

Babou
- 151
- 1
- 12
0
votes
0 answers
Having to add additional dependencies to react useCallback dependency list
I'm trying to create a custom hook function that uses useCallback
function. Here's a toy example:
export function useCustomLink(link: { url: string; description: string }) {
const [updating, setUpdating] = useState(false);
const…
0
votes
1 answer
Unable to get updated value in form onsubmit callback / Shopify Polaris React Component
Issue summary
Hi Team,
I am new to Polaris and trying to create react signup form with following code
import React, { useCallback, useState } from "react";
import {
Button,
Form,
FormLayout,
Layout,
Checkbox,
Card,
Page,
TextField,
}…

Vengat
- 119
- 1
- 9
0
votes
2 answers
State doesn't update on React Native
I'm doing the notification page of my react native app. It has infinite scroll and "pull to refresh" options. Entering to the page it works, and it works also pulling to refresh.
The problem occurs when I scroll down because it seems it calls server…

panagulis72
- 2,129
- 6
- 31
- 71
0
votes
1 answer
React functional component does not change as soon as value changes
I've made a react component for reset password page. After a reset token is sent to the user email, the reset page has three inputs: token, new password and confirm password. The latter two are hidden until a sha256 token is entered in the token…

Aakash Meshram
- 105
- 9