Questions tagged [usecallback]
251 questions
0
votes
0 answers
Sending input value from grandchild to child and parent element with Typescript React Use Callback method
---It is Grandchild value that i want to send child component then Parent component with typescript React ----
const [mapDestinationfilter, setmapDestinationfilter] = React.useState([]);
const onChange = (e) => {
const value =…

Farhad
- 31
- 1
- 3
0
votes
2 answers
React useCallback is only working once between 2 child components
function Route()
{
const [Items, setItems] = useState([]);
const [status, setQuotestatus] = useState(true);
const [quotation, setQuotation] = useState({quoteNo: "", type: "Project", quoteDate: "", validity: "", total: 0});
const callback…

Ameen NA
- 39
- 1
- 1
- 5
0
votes
0 answers
useCallback hook: Variable in dependency behaves differently with 2 declaring method
I'm new to React & learning to using useCallback. Here's my problem:
In the code, I check if the temp is true. If yes then the num will be increased by 1 whenever I press a button (which I have already pointed to the callbackButtonHandler). Because…

chaukhoa97
- 35
- 5
0
votes
1 answer
useCallback dependencies for array of items
I have a list of cards. When I add them to favourites by pressing a button, it changes the color of that button.
However, I just want that particular card to re-render after adding to favourites.
const addFavouriteHandler = useCallback((id: number)…

Lokesh Bajracharya
- 457
- 2
- 8
- 19
0
votes
2 answers
useRef is not updating sometime and print just object
I am trying to use useRef and useCallback together but my useRef is not updating sometime, it seems. It is actually weird and it happens only sometimes. Even if I use normal ref operating, it will behave the same.
function useRefCallback() {
const…

Phyo
- 27
- 8
0
votes
1 answer
React stale state useCallback
I am using the geolocation API inside my functional component, and my success and error callbacks for geolocation.watchPosition(success, error) have conditional code that is dependent on some state value that is going to change.
I do not want to…

Sam
- 375
- 1
- 5
- 15
0
votes
1 answer
how can i get useState value inside useCallback (react hook)
i can't get the useState value that inside of useCallback. when i run the code below,
import React, { useCallback, useEffect, useRef, useState } from 'react';
const DBLab = () => {
const [hashHistory, setHashHistory] =…

importJWE
- 73
- 7
0
votes
1 answer
Unbale to prevent re rendering using useCallback and React.memo
I am using React Native version 0.64. I have a page which consist of one mapview and two buttons. using that two buttons I am updating the state, but whenever I am updating the state the map component is getting re-rendered. To prevent re-rendering…

Sandip Nag
- 968
- 2
- 18
- 34
0
votes
2 answers
Custom hook that updates all components that use it in sync
I'm trying to create a Switch component in react that uses a custom hook. I want other components to use that same custom hook so that they are updated when the Switch is clicked. To do that I've created this custom hook:
function useToggle() {
…

Chayemor
- 3,577
- 4
- 31
- 54
0
votes
0 answers
how to useCallback in useEffect when fetching data in async mode
can any one help me with that
actually i am trying to add useCallback function but it's seems not working it's loading
not showing any data
every time i change page and came back to the "users" url it's start re-render
plz help me with this
plz if…

Frank Maruf
- 1
- 2
0
votes
1 answer
Prevent rerenders for objects with React.memo, useCallback, useMemo
Prevent rerenders for primitive values works fine (React.memo) but problem starts when I try pass object to child component. I tried use useMemo and useCallback but with no success.
Only solution that works it to use JSON.srtingify() to pass data…

CodeJoe
- 262
- 2
- 10
0
votes
1 answer
can i memoize custom hook which is graphql query in react?
// useMe.tsx //
import { gql, useQuery } from "@apollo/client";
import { meQuery } from "../__generated__/meQuery";
export const ME_QUERY = gql`
query meQuery {
me {
id
email
my_workspaces {
title
}
}
…

jy kim
- 17
- 5
0
votes
1 answer
Our useEffect doesn't call our fetch function
We're trying to fetch data from openweather.org, we want to call a fetch from within a useEffect that runs just once when the page is loaded. We want to be able to call the fetch again from a search form, so to avoid dublicate code we don't want our…

crashdelta
- 3
- 5
0
votes
1 answer
Why is child component re-rendering if only prop has useCallback?
Child component only is supposed to re-render if its prop (numberModifier) is modified.
numberModifier is using useCallback with no dependencies. Thus, it never changes.
In order to test this, I modify the value of “online” (inside Application)…

dragon25
- 33
- 5
0
votes
2 answers
Why setTimeout is not triggering inside useCallback ReactJS
Want to write a function that triggers if user is scolling, but it seems that setTimeout isnt being triggered in this case. It should set the state to false when user is not scrolling.
const handleScollTab = useCallback(
() => {
…
user13914915