Questions tagged [react-usememo]
169 questions
0
votes
1 answer
How can i wait for a value to be set from useEffect?
We are using useMemo and useEffect when fetching an array of data. In the first file im setting a const with results from the hook (second file). But the results gets set twice and the first time the result is an empty object.
I would need it to be…

MCLarge
- 45
- 6
0
votes
1 answer
How to change number of columns responsively using useMemo hook in react.js?
It returns fixed column numbers, when you add more contacts it will always be 3 columns, and I need to change numbers for responsive design, like it should be 2 columns or 1 based on screen resolution.
const contactsCollsMemo = useMemo(() => {
…

Perizat Sabitbek
- 1
- 1
0
votes
0 answers
Props not being passed from Parent to Child element
I have a question regarding data passing between parent/child element.
The parent element StylePage retrieves data via SWR which retrieves the data without problem and the application is able to display it with a Text. Problem is that it isn't being…

DLO
- 914
- 1
- 13
- 30
0
votes
1 answer
useMemo not running when "data" from Apollo useQuery hook returns a new value for "data" on which useMemo is dependent
I have a component that uses useQuery Apollo Hook to fetch data from a GraphQL API. This component also has a useMemo that has the data variable returned from the useQuery Apollo hook as a dependency.
The useMemo runs initially on the first render…

Nadish Sood
- 11
- 1
- 2
0
votes
1 answer
useMemo computationally expensive calculations
I've created a sandbox using useMemo to optimize a mock expensive function follow Kent C Dodds example from this post. Memoisation doesn't seem to be working. Any ideas why?
https://codesandbox.io/s/usememo-rfphn?file=/src/index.tsx

Brad Woods
- 1,507
- 2
- 12
- 30
0
votes
0 answers
useContext triggers rerendering without changes
I have following react-component:
type Props = {
country: string;
electricityValues: number[];
activeStep: number;
setActiveStep: React.Dispatch>;
}
const EmissionsMemoized = (props: Props) => {
…

Hans
- 1,162
- 11
- 18
0
votes
1 answer
React, Have UseMemo work correctly with textbox
The following UseMemo is not working. I am trying to memorize the square X^2 of number values. I type 3, to calculate data, then enter 4, and then 3 again. It recalculates each time. How can I fix this?
function App() {
const [number, setNumber] =…

mattsmith5
- 540
- 4
- 29
- 67
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
3 answers
How to memoize a value based on a property of an object in React?
In my functional component, I want to memorize some value which depends on Id property of an object:
obj={
innerProperty:{
id:1
}
}
useMemo(()=>someComplaxFunction(), [obj.innerProperty.id])
I want to do something like this, but the issue…

Madhur Bansal
- 726
- 2
- 8
- 14
0
votes
1 answer
How to use ReactJS's useMemo() to freeze the component's content?
The short question is: how do we freeze a component's content, probably by using useMemo() and telling it to freeze the content?
That's because useMemo(fn, []) takes the array to do a diff of values to decide whether to use the memoized value. It…

Stefanie Gauss
- 425
- 3
- 9
0
votes
1 answer
React component works fine, but attempting to use useMemo() results in an error
I have a form with a meeting booking inside it. Part of this is a calendar component, that has a fairly complex UI.
This works fine.
As React users will know, react…

mikemaccana
- 110,530
- 99
- 389
- 494
0
votes
2 answers
How can I persistently memoize across renders of a React component?
I'm using React with hooks. I have an expensive function that I'd like to memoize.
I know React comes with useMemo(), but the values I need memoized are calculated once, each, on their first render. So there's no point to memoization within the…

mikemaccana
- 110,530
- 99
- 389
- 494
0
votes
1 answer
Converting shouldcomponentupdate to memo in React
What will be the equivalent code using React memo?
shouldComponentUpdate(nextProps) {
if (this.props.addCourse !== nextProps.addCourse || this.props.level !== nextProps.level ) {
return true;
} else {
return false;
}
}

Avinash Toppo
- 349
- 1
- 2
- 10
0
votes
0 answers
Using React.useMemo to pass arrays to react-table, one of the useMemo's returns an empty array due to renders
I am hitting two different api's for my data and am using React memo to pass them as variables into a react-table useTable function. When I run all my code without the useTable, the reactMemo seems to work, I can console the two variables that I am…

Anders Kitson
- 1,413
- 6
- 38
- 98
0
votes
1 answer
in redux-react on initial component render dispatched and state is changed
I have created a login component, and there is a state Auth with redux
that and reducer to update the Auth state (initally it is set as FALSE)
but on initial render dispatch is called 4 times and state is updated to TRUE
i have tried useMemo, but…

Vijayashankar Aruchamy
- 103
- 2
- 12