All Questions
Tagged with use-state or react-hooks
38,748 questions
-6 votes
0 answers
110 views
What are problems with this pattern in these situations? What is a less problematic pattern? [closed]
I have a particular situation where I need a component (ViewOne) to update a ref, and read from that ref on mount. I also have a second component (ViewTwo) that needs to render different content ...
2 votes
1 answer
67 views
React 18 streaming chat messages updating with stale state
i’m building a small AI chat ui in react (next.js app router, react 18) that streams tokens from my backend (openai style stream). basic flow: user types a prompt i push the user message into ...
Best practices
0 votes
3 replies
72 views
Using setTimeout within useEffect() to debounce searching in react native pagination
I am planning to implement pagination into my project for my data from Supabase, I had the idea that since there are different parameters (such as search text, page number, filter) that I should use ...
-3 votes
0 answers
36 views
Updating state in React.js but there is a lag of one element [duplicate]
const onChangeFn = (e,i) => { const data = e.target.value; if(/^\d?$/.test(data)){ let new_Array = [...values] new_Array[i] = data; setValues(...
Best practices
0 votes
2 replies
143 views
When should I use useTransition() or startTransition in React
I have been exploring the useTransition() hook and the startTransition() method provided by React with version 18+. The documentation states that we can de-prioritize state updates using them so that ...
0 votes
0 answers
126 views
Promise's behaviour inside component without using `use` hook [closed]
In this example from react docs, I can remove use hook from const messageContent = use(messagePromise); leaving it like this const messageContent = messagePromise; and it still works (no error is ...
-2 votes
0 answers
18 views
Implementing useState to set variable as the results of an Axios call in useEffect [duplicate]
I am attempting to retrieve a search result from a MySQL database with Axios. res.data is populated with the correct data but when I use my useState setter inside the useEffect, my searchRes variable ...
3 votes
1 answer
92 views
useEffect is running a function an additional time instead of once per if statement
I have a modal. This modal opens after a user uploads a CSV. They can then make changes to the entries or delete them. The user can Confirm & Continue (go to next page, modal closes) or Upload New ...
3 votes
1 answer
94 views
useOptimistic: How to handle race conditions when multiple optimistic updates affect the same state slice?
I'm building a collaborative task management app using React 19's useOptimistic hook. Multiple users can update task properties (status, priority, assignee) simultaneously. I'm running into race ...
0 votes
2 answers
140 views
Why does useEffect on [] gets called on hot reload?
app/page.tsx "use client"; import { useEffect, useRef } from "react"; import { foo } from "./OrdersModuleFoo"; import React from "react"; const OrdersModule: ...
2 votes
1 answer
94 views
React - useContext - code executed 2 times in provider
This is my structure about code: src App.js pages ConfigurationPage.jsx provider ConfigurationProvider.jsx context ConfigContext.jsx Explain bug: The code is executed 2 times in provider. The ...
0 votes
1 answer
125 views
useEffect not running when ref.current is removed from dependency array in React
I'm using a DynamicForm component with a ref in a React functional component. I want to update the form once my Firebase collection is loaded. Here’s the relevant part of my component: const ...
-1 votes
1 answer
402 views
Is it still necessary to use 'useEffectEvent' function [closed]
When I read the react document, I found a new feature useEffectEvent, which raised a question. If I use responsive variables A and B in useEffect, but I am very sure that it is meaningful to make the ...
2 votes
1 answer
103 views
Prevent useEffect from running on token state change immediately after login in React
Im developing a new app and tried to implement authentication with JWT myself (and with ChatGPT). I will try to explain it as briefly as possible and what I think is happening. // Render the app const ...
0 votes
1 answer
96 views
How do I properly use `useEffect` cleanup in React to avoid memory leaks? [duplicate]
Can't perform a state update on an unmounted component. I understand that this warning happens when the component unmounts before the asynchronous request finishes, and then setState (or in my case ...