Questions tagged [react-usememo]
169 questions
2
votes
1 answer
How does memoization break on Redux createSelector() across multiple components?
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
2
votes
1 answer
Should I remove all unecessary usage of usecallback and memo in a React app?
im working on a relatively large React codebase and I've seen that the previous developers used memo and usecallback liberally with the thought that by using these would improve performance. Obviously not, here is an example
export default function…

fardown
- 713
- 2
- 12
- 23
2
votes
1 answer
Access latest state in useMemo
I am using react-quill, and it's requirement is that modules prop must be cached and shouldn't change. I am using useMemo hook to memoize it. The object is:
const modules = useMemo(() => ({
key: {
value: {
handler: handlerFunc
}
…

U-Dev
- 1,296
- 5
- 19
2
votes
1 answer
Can we use useMemo when memoized object is used in useEffect?
Imagine this case.
A hook that receives an object and based on the object's properties does some computing and returns the result.
export const useTestHook = (someOject) => {
const [updated, set] = useState({ val1: null, val2: null });
…

Kremdas
- 80
- 2
- 7
2
votes
1 answer
How to use useCallback, useMemo and React.memo when dependency is an object?
I have useMemo when one of its dependencies is an Object that I get from the server, so even when the content of the object is the same - the useMemo is called over and over again in each sync from the server because the object itself is different…

user2993539
- 375
- 1
- 3
- 14
2
votes
1 answer
How can I use useMemo dependent on the webapi
I have a webapi invoked that is working properly:
const [pItem, setPItem] = useState([]);
const [weight, setWeight] = useReducer(weightHandler, 0.0);
useEffect(() => {
setLoading(true);
let mounted = true;
(async function () {
…

albert
- 219
- 4
- 13
2
votes
1 answer
React.useMemo is re-rendering all items in array
I have a react component that stores a set of fruits in useState. I have a memoized function (visibleFruits) that filters fruits. I map visibleFruits to the dom.
The problem is, when i check a fruit, all visible fruits re-render.
I am expecting that…

Jar
- 1,766
- 1
- 21
- 27
2
votes
1 answer
Only show matching string in array when using 'useMemo' in react
I have an autocomplete input field and running into issues when initially hiding the output in my array. Instead of showing all my items when mounted, I just want to show the matching string. Leaving my state empty const [filteredRecipes,…

user992731
- 3,400
- 9
- 53
- 83
2
votes
2 answers
React - useMemo giving warning although program is running fine. (useMemo has an unnecessary dependency)
First of all sorry for bad code. I am new to React, so please excuse me :P. Here I have created 2 buttons, "add" and "Change fake". When I click on "add" it will not re-render child component and when I click on "change fake", It does re-render the…

EaGle Network
- 103
- 7
2
votes
1 answer
state in custom hook not updating
I am not able to get an updated state from the custom hook.
the example is simple. this is a custom hook allowing to switch from dark to light theme
inside the custom hook, I use useMemo to return a memoized value, but this does not seem to update…

user9958772
- 147
- 2
- 9
2
votes
2 answers
Can a useMemo memoized value be updated with useEffect from within the component?
I'm trying to render data that must be passed through useMemo. I get the data from an api call so I call useEffect. The initial render works returning an empty array but once I call the api, data is not updated.
import React from 'react'
import…

rsgmon
- 1,892
- 4
- 23
- 35
2
votes
1 answer
Are child components of a memoized component memoized too?
Does the child component returned from useMemo or wrapped in React.memo() are memoized too?
(Apologies, this might be a silly question)
For example:
React.memo( );
Here the Parent is memoized, is the Child too memoized?

Benison
- 157
- 1
- 2
- 17
2
votes
0 answers
React: is useEffect always the correct way to go?
I am currently asking myself, if useEffect is always the right way to go.
I am thinking about that, because of my current project.
Imagine you have to following:
a state query which is just a query for backend. A query also knows a sorting. This…

Jan Höck
- 219
- 3
- 12
2
votes
1 answer
When to use useMemo and useCallback for performance optimization?
Consider i got such example:
import React, { useMemo, useCallback } from 'react'
const Hello = (props) => {
const { firstName, lastName } = props
const fullName = useMemo(() => `${firstName} ${lastName}`, [firstName, lastName])
const…

Limboer
- 373
- 4
- 24
2
votes
0 answers
Why is my memoized React component still re-rendering?
I'm trying to understand React.memo but a bit puzzled. Thought the use case was preventing re-renders by memoizing the component? I have a memoized Child that is still being re-rendered every time.
--App
----Home [updates state via button…

Aid19801
- 1,175
- 1
- 17
- 30