Questions tagged [react-usememo]
169 questions
1
vote
0 answers
use useMemo for large tables in react without react-table
I have a table that has a big database, 2k lines +
So I had a function to filter and organize this working, but it takes 1-2 secs to filter, is it possible to do with useMemo or useCallBack since I always need to redo the database?
export default…

Collaxd
- 171
- 1
- 11
1
vote
2 answers
How does useMemo() create an id for its factories?
There is a function in React called useMemo()
const eg = React.useMemo(() => true, []);
If I included the same function twice, how would it know which memoization to return?
const eg1 = React.useMemo(() => Math.random(), []);
const eg2 =…

Seph Reed
- 8,797
- 11
- 60
- 125
1
vote
0 answers
Load JSON data with useMemo
In the following line:
it loads the json data using useMemo
import MOCK_DATA from './MOCK_DATA.json'
const data = useMemo(() => MOCK_DATA, [])
As it's mentioned in ReactTable that
It's important that we're using React.useMemo here to ensure that…

william007
- 17,375
- 25
- 118
- 194
1
vote
3 answers
React - how to replace useCallback hook with useMemo?
I am reading this article about memoization in React, and I wonder how can I translate and use useMemo instead of useCallback hook. In particular for this example:
{console.log('Really Skinny Jack')}, []) } />
Where…

Ludwig
- 1,401
- 13
- 62
- 125
1
vote
1 answer
Confused about the strange performance of useMemo Hook in React
This is my own hook which is used to realize debounce in React Hooks
import { useMemo, useRef } from "react";
import { debounce } from "lodash";
export function useDebounceFn(fn, wait) {
const fnRef = useRef(fn)
fnRef.current = () => {
…

Dc.renegade
- 79
- 3
1
vote
1 answer
I Cannot Get React's "useMemo" Array of Dependencies to Work
I am trying to understand how the dependencies in React Hooks work. It sounded simple enough but in the following artificial example, I cannot get the Memo to print when the variables are updated by clicking on the "Done" text.
I believe if those…

st11x
- 11
- 1
- 2
1
vote
0 answers
FlatList inside useMemo, initalNumToRender issue
I have a FlatList inside useMemo as follows
const content = useMemo(
() =>
isLoading ? (
) : !alerts.length ? (
…

Hagai Harari
- 2,767
- 3
- 11
- 23
1
vote
1 answer
How to prevent rerendering of children inside List component of react-window
Problem
I'm trying to achieve a behaviour, when merely changed items of the list are being updated and rerendered with new data.
I wrote a component which is being updated when timer is off:
import { FixedSizeList as List } from…

Juriy
- 565
- 1
- 5
- 17
1
vote
1 answer
Why are snapPoints memorizades with useMemo react-native-bottom-sheet
Why the documentation use useCallback and useMemo to memorize the props passed for the BottomSheet, what the performance win with this?
https://gorhom.github.io/react-native-bottom-sheet/usage
import React, { useCallback, useMemo, useRef } from…

Luis Antonio tonhao_dev
- 123
- 1
- 7
1
vote
0 answers
Are there performance gains for useCallback and useMemo with redux-toolkit?
I've seen a lot of descriptions of why you shouldn't use React's useCallback with an empty dependency list (which makes logical sense), but I'm stuck trying to figure out if there are performance gains when using it alongside redux-toolkit, when the…

sernaferna
- 314
- 1
- 6
- 15
1
vote
1 answer
Warning: The final argument passed to useMemo changed size between renders. The order and size of this array must remain constant
I'm getting markers when location is entered by the user, and the markers list is then provided to the Google Maps component. Since I don't want the map to re-render everytime, I have memoized it. It only re-renders when the markers props changes.…

U. Watt
- 533
- 1
- 5
- 27
1
vote
0 answers
Is it safe to omit variables from other hooks (e.g. useContext and useNavigate) from the dependencies of useMemo?
If I do omit that, I get an eslint warning. But if this would be a problem, because they'd chage in consecutive renders than the render code in useMemo would run on each render.
Fortunately this is not the case currently, but this may change isn't…

koverg70
- 11
- 2
1
vote
1 answer
Passing a value up in react without writing state in parent
What I am trying to do:
I need price * quantity = total. I have a table with price as one , quantity as one and total as one . Quantity is a counter and needs to have its own state as rows will be added with more counters. But I need that value in…

mike
- 109
- 2
- 10
1
vote
0 answers
Memorizing values upon an async call in react
I'm trying to memorize some values in a react component because it's re rendering even when data hasn't changed (and wont change). Using useEffect + useState the data displays correctly, but the functions are triggered each time the component is re…

yieniggu
- 384
- 1
- 7
- 20
1
vote
1 answer
The dependency array of useEffect, useCallback, useMemo
I'm so confused of the dependency of React Hooks.
Here's the example:
const memorizeValue = useMemo(() => {
return {
count,
setCount,
}
}, [count, setCount])
In React documentary:
Note
The array of dependencies is not passed…

Baiwei
- 235
- 2
- 7