Questions tagged [react-usememo]
169 questions
0
votes
1 answer
The array passed as the value prop to the Context provider (at line 8) changes every render. How i can fix this?
I am using context and HOC. I am passing the state internally via context to the HOC and it throws an error like this. You need to add useMemo. But I have no idea how exactly to do it. Can anyone tell me how can I fix this please. 8:32 error The…

Anta
- 97
- 8
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…

ryder80
- 1
- 1
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…

XxXxXxXx
- 1
- 1
0
votes
1 answer
when the page first renders it shows the whole list, then it checks and deletes the ones I subscribed to
I have a problem with react useMemo.
const [cardlist, setCardList] = useState([]);
const [subs, setSubs] = useState([]);
useEffect(() => {
handleCardList(); // for rendering cards on page first time
}, []);
const uniqCard =…

Menectra
- 3
- 1
0
votes
1 answer
Why can't I add non react variables(state, props) such as normal variable, external functions in dependency array of useMemo?
Please look at the commented code. Why can't I use name as dependency in useMemo?
I want to stop useEffect rerendering the page again just because some referential equality of a variable is changing that's why i used useMemo in themeVar…

Devil PL
- 1
- 1
0
votes
1 answer
React re-downloads image after every render
Edit:
The reason for re-downloading of resources was related to cacheing of images - I had previously enabled Disable cache in chrome dev tools, disabling it solved the issue!

Viliam Popovec
- 168
- 9
0
votes
1 answer
Is useMemo asynchronous like useState Hook?
Usually we cannot use the state value of useSate immediately after setting it. Is it the same for useMemo?

RVK
- 43
- 1
- 7
0
votes
1 answer
React Table UseMemo
I am trying to implement the reacts useMemo in order to re-render the table when the delete button is clicked for a row. The delete works and I can see that my data array decrements with each click of the delete button and the table re-renders if I…

franxoliveiraa
- 1
- 1
- 2
0
votes
1 answer
useMemo hook always True even the location.pathname change
I am trying to render a specific Layout if the location change and I'm using the useMemo hook to validate the route and render the based on this value but it always returns true even the route change for example the new route is…

Abodi Atrash
- 3
- 3
0
votes
1 answer
how to wrap renderItem function of flat list with useMemo
there is simple renderItem function, all I need is wrap it with 'useMemo',
but encounter an error as seem below;
original:
const renderItem = ({ item, index }: { item: any; index: number }) => {
return (

TrypicalDev
- 101
- 8
0
votes
1 answer
ReactJS useMemo inside function
I have this function:
const handleSearch = (event) => {
const currentValue = event?.target?.value;
const filteredData = searchTable(currentValue, originalData);
setDataToTable(filteredData);
};
I tried to use useMemo() to memoize the value of…

pmiranda
- 7,602
- 14
- 72
- 155
0
votes
2 answers
Using useSortableData based on useMemo() after data update in React app
I've made application based on this example
https://codesandbox.io/embed/table-sorting-example-ur2z9?fontsize=14&hidenavigation=1&theme=dark
But also I need data update in table (adding, removing)
I use
const { items, requestSort, sortConfig } =…

George
- 87
- 3
- 10
0
votes
1 answer
How to memoize each element in an Array.map() in React? (with useMemo)
I have the following element:
{user.name}
I can memoize it by doing: useMemo(() => ({user.name}
), [user]); Now, let's say I have the following code: users.map((user) => ({user.name}
)); How can I memoize each element…
Daniele Molinari
- 541
- 6
- 29
0
votes
1 answer
Can I passing function instead of array as second argument to React.useMemo
Can I pass array.map(val) => val instead normal array as second argument to React.useMemo() hook?
I'm receving a nested object from server as response and I can't give this response for second argument because useMemo() just check instance of…

radinvafaei
- 65
- 7
0
votes
1 answer
prevent re-render using useMemo
I am doing a fetch every 30 seconds and saving the response in my redux state. What i want to do is prevent re rendering of the component if the response is same as the previous one. To do this i have tried useMemo hook.
const details =…

CraZyDroiD
- 6,622
- 30
- 95
- 182