Questions tagged [react-usememo]

169 questions
2
votes
0 answers

React optimization: what is the goal of applying useMemo to useState return values?

In this article on state management with context API, the author applies useMemo to useState return values this way: function CountProvider(props) { const [count, setCount] = React.useState(0) const value = React.useMemo(() => [count, setCount],…
Louis Coulet
  • 3,663
  • 1
  • 21
  • 39
2
votes
0 answers

Need to wrap every useMemo dependency in a useCallback

I hope someone can help me. I tried to find the answer to my question but I couldn't, so if it is there and I couldn't find it, I apologize in advance. So, I have an expensive operation that depends on 3 objects stored in the redux store. Since it…
DiegoTArg
  • 452
  • 1
  • 4
  • 14
1
vote
1 answer

rendering of the child component

I have a child component: const MemoModalWindow = memo(ModalWindow) I pass props to it show={show} - boolean, handleClose={handleClose} - function, rowValue={**first**} -…
Romio
  • 7
  • 4
1
vote
0 answers

How to rerun useEffect that depended on the object whose properties I do not know it's attribute

I wanted to rerun useEffect if the object value changed. And when I searched, I found the solution to use (useMemo) because an object is a reference and a solution like this. // We want to rerun useEffect if name or age are changed const…
1
vote
0 answers

Keep track of multiple arrays in react useMemo and execute separate function for individual array

I currently have two arrays which updates based on the onClick event. I want to keep track of this array updates through useMemo ,I want to know which array is getting updated on every click but I want to execute separate function for each array…
Divakar R
  • 773
  • 1
  • 8
  • 36
1
vote
0 answers

React 17 useMemo create a losted instance of object

[EDIT] Thanks to @dbuchet for his anwser. The problem comes from the fact that in StrictMode in dev mode only, everythings is running twice. [PROBLEM] I just got a weird beavour in React. My context : I want to create an EventSource for work with…
1
vote
2 answers

Can I run a function after useMemo return is on the screen

I'd like to get some kind of call back once memoizedTodos are displayed on the screen. or execute handleOpen function once memoizedTodos are displayed on the screen. Right now what I'm displaying on the screen is just the text. but you could imagine…
Happy1234
  • 537
  • 3
  • 15
1
vote
1 answer

What is the correct way to memoize this useEffect dependency?

I use useEffect to listen for a change in location.pathname to auto-scroll back to the top of the page (router) when the route changes. As I have a page transition (that takes pageTransitionTime * 1000 seconds), I use a timer that waits for the page…
singing
  • 65
  • 6
1
vote
1 answer

useMemo being called without any change in dependency

I am using React 17 and trying to move some redux data to react query. One of the common functionality in redux is to massage the api data and store it for all the consumers. I am trying to replicate the same functionality via react query. If the…
Probosckie
  • 1,585
  • 4
  • 25
  • 40
1
vote
1 answer

How to use useMemo and use Effect efficiently to load React Table data from an api using axios

I have a table that displays users List. It fetches the data from my backend server. when i try to fetch data its takes (4 render ) to Get the actual data. How can i use useEffect and useMemo to avoid re-render. iam using a custom hook to fetch the…
1
vote
1 answer

Apollo GraphQL useQuery hook triggered with old variables

I am trying to make some reusable Apollo hooks and simplify the APIs with some encapsulation. So my idea is to have the useQuery hook inside of a custom hook. In my case I need actually the useLazyQuery hook: export const useGetSomething = () => { …
Michał J. Gąsior
  • 1,457
  • 3
  • 21
  • 39
1
vote
1 answer

fluent ui - In details list there is loss of selection state if state is modified inside Selection onSelectionChange callback

While using fluent UI's details list, I am setting both setKey and getKey while overriding the on selection changed method. But on the double of the row or on Item Changed, the correct selected row item is not passed. Please advise. Edited: I went…
1
vote
1 answer

Problem with Mobx (TS) using with React Functional Components

Here is the problem. I have simple todo store: import { makeAutoObservable } from "mobx"; import { Todo } from "./../types"; class Todos { todoList: Todo[] = [ { id: 0, description: "Погулять с собакой", completed: false }, { id: 1,…
luckyme-
  • 13
  • 2
1
vote
2 answers

How to use useMemo in this example?

I'm struggling with problem chaning const variable to const with useMemo. I tried some example from docs and some tutorials and nothing worked for me. This have to be easy... const bottomSheetOptions: BottomSheetAction[] = [ { label: …
Mikołaj Wittbrodt
  • 399
  • 1
  • 4
  • 18
1
vote
0 answers

Memorising async server call in react

I have an array of widgets for the app and each widget component is calling API for its data. There are multiple type of widgets, charts, lists, tables, etc.. and situation dictates that parent page cant call data itself so, children components…
Mladen Milosavljevic
  • 1,720
  • 1
  • 12
  • 23