Questions tagged [usecallback]

251 questions
0
votes
1 answer

React Hooks useCallback and useEffect causes infinite loop in react application

import axios from "axios"; import { useEffect, useState, useCallback } from "react"; export default function App() { const [user, setUser] = useState([]); const getUser = useCallback(async () => { let { data } = await axios.get( …
0
votes
1 answer

How to make memoization work with useCallback() and Redux-Toolkit createSelector()?

According to the documentation here: Creating Unique Selector Instances: There are many cases where a selector function needs to be reused across multiple components. If the components will all be calling the selector with different arguments, it…
Chong Lip Phang
  • 8,755
  • 5
  • 65
  • 100
0
votes
1 answer

useCallback equivalent in React class component

I have a large code base in React class components and some are so complex, that I do not want to refactor them to React functional components. For one function, I need memoization, so my question is: Is there an equivalent for React functional…
user3601578
  • 1,310
  • 1
  • 18
  • 29
0
votes
0 answers

Stop re-rendering mapped lists when parent state changes

How do I avoid mapped child components from re-rendering at onParent state change? I have already tried memo in child component and useCallback in parent component to memoise function that updates the state with an empty array as dependencies. I…
0
votes
1 answer

react-native validation with useState and useCallback

I use useCallback validation for useState value, but that has get value delay. This is my useState code const [loading, setLoading] = useState(false); const [amount, setAmount] = useState(''); const [rate, setRate] = useState(''); const…
joshua.kim
  • 373
  • 3
  • 11
0
votes
1 answer

Why the React List component gets rendered twice?

I have a React code as below: import React, { useState, useCallback } from "react"; const initialUsers = [ { id: "1", name: "foo", }, { id: "2", name: "bar", }, ]; const List = React.memo(({ users, onRemove }) => { …
injoy
  • 3,993
  • 10
  • 40
  • 69
0
votes
2 answers

useCallback Implementation

I was just wondering how come useCallback cannot pick up the latest state value from the component. Isn't component's state is present in the outer scope. const [x, updateX] = useState(2); const handleChange = useCallback(() => { …
Avan
  • 366
  • 3
  • 17
0
votes
0 answers

Memoization of custom useLocalStorage hook

I'm creating a react app that has a few states that I want to read/save to localStorage. I've created a useLocalStorage hook, and it's working, but I'm concerned that I'm reading from local storage every time the App component re-renders. I'd…
0
votes
1 answer

Event handler function not updating, state undefined inside function scope

I am working on a scheduler app and for that I am using the kalend calendar component library. The usage looks something like that
gobsej
  • 55
  • 5
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 remove items from the shopping cart at index using the useCallback hook

I am trying to add a functionality that remove an item from the shopping cart component by clicking the onClick that fires the removeProductFromCartAtIndex useCallback function. So far I managed to add items to the shopping cart successfully but…
0
votes
0 answers

How to Use useCallback() Hook Efficiently in FlatList

I just recently learned how to use useCallback() hook. Right now I have an application to render a component called "Events" in the FlatList React Native component. I looked up posts on how to use useCallback() in a FlatList component and I…
Quan Khuc
  • 1
  • 3
0
votes
4 answers

Problem using useState inside useCallback hook

I'm having a problem where a useState hook "setSelectAll(!selectAll)" inside a useCallback function updates the value but the conditional below that sentence is using the old selectAll value, so i have to make two clicks to make it work, and I dont…
0
votes
1 answer

Problems with multiple rerendering in React - Add to Favourite List example

I am building a small framework for e-commerce or blog app using React. One of the features of this framework is an "Add to Favourite List" function. The app tree works as follow : App file stores the selectedItem chosen by the Menu, and then App…
0
votes
1 answer

React Component re-renders in iOS but not in Android

I am developing an app using React Native and I'm struggling to figure out why my component re-renders in iOS but not in Android. I'm expecting it not to re-render, which means that the Android behavior is the one I'm looking for. The problem is, I…