30,711 questions
1
vote
1
answer
23
views
React Accessing another component’s DOM nodes
Going through react.dev learning tutorial, I noticed something not quite right about accessing another component’s DOM nodes.
https://react.dev/learn/manipulating-the-dom-with-refs#accessing-another-...
1
vote
1
answer
40
views
useState issue with axios instance in React [duplicate]
I have the following React component, it works very weird! Everyhing inside useEffect hook is correct (console.log shows correct value of the instance), but After calling setApiInstance with the newly ...
2
votes
3
answers
41
views
How to use useState, Dispatch input?
Consider this code:
const [seconds, setSeconds] = useState<number>(START_VALUE);
useEffect(() => {
const intervalId = setInterval(() => {
setSeconds((previousSeconds) => ...
-1
votes
1
answer
24
views
What are the potential consequences of not returning clearTimeout? [duplicate]
The question is asking about the potential negative effects of not returning the value returned by the clearTimeout() function in JavaScript.
import { useEffect, useState } from 'react';
function ...
0
votes
0
answers
68
views
i try to logout from my dashboard components, it stuck on dashboard with loading and all the dashboard content remove
Here is my code to get the dashboard form backend using useEffect and then the handler to handle the logout button
After few time if I reload the page then its redirected the login page.
import React, ...
1
vote
1
answer
27
views
Material UI: DataGrid server-side pagination flickering data when using swr
I want to display server-side paginated data on a Material UI DataGrid with data fetched using swr. I've been working through MUI's introduction example for server side data in DataGrid which is using ...
1
vote
2
answers
41
views
React Redux: Login Form Flickers on Page Refresh Despite User Being Authenticated
I'm building a React application using Redux for state management. My app checks if the user is already logged in by fetching authentication data from localStorage and dispatching it to Redux. However,...
-1
votes
0
answers
17
views
can't show data on my custom react native picker
I have try to make custom Picker for my app . all are working fine but when i click on Category it show list of item but when click on that it did not retrieve data to show replace Category to ...
-1
votes
1
answer
21
views
Why does my React useEffect hook run multiple times even with an empty dependency array? [duplicate]
I'm working on a React project and encountering an issue with the useEffect hook. My goal is to fetch data from an API only once when the component mounts. However, the useEffect seems to run multiple ...
-1
votes
0
answers
15
views
React complains about different number of hooks used while switching between routes
I'm trying to implement MVVM pattern in my React application. Let's assume for simplicity that the project structure looks as follows:
src/
- mvvm-stuff/
- ...
- Component1/
- Component1View.tsx
...
0
votes
1
answer
42
views
How to unit test a form using the useActionState hook?
I want to test a form with the useActionState hook. It does use simply async function, not a server action. I would like to assert the state to be incremented, but the test fails even before I can ...
-1
votes
2
answers
43
views
Conditionally using custom React hooks?
I have two custom React hooks that fetch different data and parse it. Both hooks return an object of the same type. I have a component that displays that data and depending on a "variant" ...
1
vote
2
answers
52
views
How to call a callback prop when another prop changes without omitting useEffect dependencies?
I have a simple dialog component that takes an open prop to control whether the dialog is shown or not, and an onOpen prop which is a callback to be run every time the dialog opens.
I can achieve this ...
-1
votes
0
answers
18
views
How to prevent react race condition after clearing a state array then appending values to it recursively after react router page change [closed]
works perfectly when props.code updates unless it updates as a result of the page changing via react router, then it includes extra junk before the correct output.
testOutput.tsx:
const runTest = (...
-1
votes
0
answers
22
views
React: Function call Working when called using UI component but not using Keyboard shortcut
I am building a React application where a MenuBar component has both UI buttons and keyboard shortcuts to trigger file-saving functions (Ctrl+S for Save, Ctrl+Shift+S for Save As).
The saveFile ...
0
votes
0
answers
26
views
How to prevent double-fetch while preserving interdependent dropdown and date picker functionality in React?
In my app, users can view data by configuring various filters, such as:
Selected Date (via a date swapper component)
Selected Period (options: Days, Weeks, Months)
Selected Fields
These filters are ...
2
votes
0
answers
20
views
My browser localstorage clears everytime i refresh
Welp, creating a time block app, and I want the saved timestamps/blocks to be present upon reload, written the appropriate code - I guess
whenever I add a time stamp/block, it shows in the application ...
-1
votes
0
answers
33
views
Maximum update depth exceeded ReactJS
I'm here because I'm having a problem in React with this :
import { useEffect, useState } from "react";
import Clear from "@mui/icons-material/Clear";
import KeyboardArrowDownIcon ...
2
votes
2
answers
57
views
Context Provider not passing value to children
I am trying to create a parent/overarching context. The purpose of the context is to store UserInfo which should then be available to all children.
UserInfo is set by getting config from an API.
...
0
votes
1
answer
36
views
Does does a useEffect and useCallback act when both have same dep(s)?
can someone help me with this question on behavior, here is a made up code snippet
const [accountId, setAccountId] = useState(null);
// accountId gets set in code not shown here
const ...
0
votes
0
answers
50
views
How to exit app when back button is pressed and drawer is opened?
The goal is to ensure that when the drawer is open and on pressing the back button should exit the app instead of closing the drawer. However, the issue is that the BackHandler is triggering even when ...
0
votes
2
answers
47
views
will useEffect setup function run every time re-render if not setting the dependencies?
I was learning useEffect hook of React recently, and I tried to write a function with useState and useEffect to see how different kinds of useEffect dependencies works. Below is my code:
import { ...
-2
votes
1
answer
27
views
State not updating in combination of useEffect [duplicate]
I am making an chat application in that I want to fetch chats but this problem is coming. response.data is coming fine but state is not updating and null is printing for console.log("chats ...
-1
votes
1
answer
33
views
Trigger useEffect on second pathname change [duplicate]
I want to scroll down below the hero block when a user changes the page. I have this code so far in my App.jsx:
const { pathname } = useLocation()
const paragraphRef = useRef(null)
useEffect(() =>...
-1
votes
1
answer
25
views
is There a way to manage data interlinking hooks work in sync within a component?
As I am beginner to react, please give your thoughts...
I have two hooks:
const {data, setData} = useHook1();
const hook2data = useHook2(data.name,{...options});
I am having the above two hooks in ...
0
votes
0
answers
33
views
useState vs useRef in terms of performance in React multi-input forms [duplicate]
When a state changes for one of the inputs, the whole page is not "rerendered", just that input field, right ? Would useRef give faster performance because there are no renders besides the ...
-1
votes
0
answers
27
views
Why object's array act like it does not have values?
I have a simple user login system in my web app. The Trip Collection page is the same whether the user is logged in or not. If not, the page simply not displaying the values. My problem is, when I ...
-2
votes
1
answer
45
views
How to pass a axios response to a function
I try this code and get an infinite loop
request.jsx
import { useEffect, useState } from 'react';
import axios from 'axios';
export async function getCategories() {
const [categories,...
0
votes
1
answer
35
views
How to change value from either inside or outside a component
I want to be able to change a value from both inside and outside a component.
Below is a copy of my attempt, from https://codesandbox.io/p/sandbox/42xrs2
The problem is self documented in the sandbox, ...
-2
votes
0
answers
59
views
Why doesn't the data update? [duplicate]
const NotiMainScreen = ({ navigation }: NotiMainScreenProps) => {
const [alertList, setAlertList] = useState<AlertData[]>([]);
const [selectMode, setSelectMode] = useState<boolean>(...
0
votes
1
answer
26
views
React checkbox gets stuck when updating parent state
I'm new to React, I'm trying to write a component that hold different groups, each group have accumulated amount of points and each group hold different checkboxes, I want that when the checkbox is ...
-1
votes
0
answers
40
views
React race conditions useeffect with same variable [duplicate]
Hi I am trying to understand what hell happened in react useEffect.
I have taken an example form official react site and just put loging there.
https://codesandbox.io/p/sandbox/6k6p5h
Anybody can ...
0
votes
1
answer
61
views
useState and custom hooks pattern [closed]
Coming from Angular I am having difficulty structuring a simple demo with React as I run into infinite loops and other side effects.
I have a GamePage.tsx (container component) that the user navigates ...
1
vote
1
answer
64
views
on submit I am getting only last array of object not complete data
I am displaying data fetched from API in table, which has inputs as fields to edit the data.
It has multiple data records fetched via API , post changes of the record I want to update the changes done ...
0
votes
0
answers
29
views
Understanding useImperativeHandle vs Manual (Forwarded) Ref Handling
I'm trying to understand the difference between using useImperativeHandle and manually handling forwarded refs in an effect when working with callback refs. I encountered an infinite rendering loop ...
-1
votes
1
answer
58
views
Getting wrong number of response render on intial rendering [duplicate]
I have written a Reactjs code . Here the first api is rendering the list of job ids . and in next api each job id is rendering the job detail of that id . here is the example .
api 1 - https://hacker-...
0
votes
1
answer
69
views
React useEffect dependency array with ref.current.property vs ref.current
I have a React component that uses useImperativeHandle to expose a Google Maps Street View panorama instance. My intention is for the StreetView ref to be attached to the Google Maps ref after it is ...
0
votes
1
answer
41
views
UseMemo still re-rendering component
The following is a simplification of a component I've written. It has two tabs, and different content is displayed depending on which tab is selected (done by a button not included here).
There are ...
0
votes
1
answer
88
views
Can we use React Hooks inside JSX component's callback like this?
Does this count as breaking the rule of hooks? It doesn't show the error/warning 'Error: Invalid hook call' and the code works normally. useEffect also mounts only once
1.✅ Call them at the top level ...
-1
votes
1
answer
46
views
Avoiding infinite loops in custom hooks without using useEffectEvent?
Here's an extract from a simple forms library I'm working on. A form has both an initial value and a current value. The current value can be reset to the initial value. Optional, upon reset the ...
-1
votes
2
answers
50
views
React Component Library - dispatcher is null useState upon running in React app
I am using vite, TS to created a react component library.
My main.tsx in component-library contains the following test component,
import React, { useState } from "react";
export const ...
-1
votes
1
answer
57
views
The state of the Next Js component is not updated
I am writing a page for the admin panel on the site. I have a component where I receive data from the backend (for example, products) and pass it to the Catalog Editor component. There, for example, I ...
0
votes
1
answer
47
views
React State Handling
I made a caching method in my react notepad and came up with a minor bug, I used useEffect to set an interval of 3 seconds and then it updates the cache holder if the heading and description are not ...
0
votes
0
answers
37
views
Spotify Web Playback SDK Works on Android and Windows but Not on Mac Chrome or iOS
I'm using the Spotify Web Playback SDK to integrate playback functionality in my app. The setup works perfectly on Android devices and Windows Chrome, but I'm encountering issues on Mac Chrome and all ...
1
vote
0
answers
35
views
How does Lazy loading works with useTransition Hook?
import { lazy, Suspense, useState, useTransition } from "react";
const AdminData = lazy(() => import("./AdminData"));
export default function Home() {
const [isAdmin, ...
3
votes
2
answers
85
views
When will the useLayoutEffect hook callback be triggered?
I have an question about when will the useLayoutEffect callback be triggered and when will the screen be drawn.
Consider the following code:
export default function CompA() {
const [count, setCount] ...
1
vote
1
answer
45
views
setInterval in useEffect triggers twice - React
I am trying to solve a cool problem in React from this video
In short, we need have 5 checkout lines in a shop, and input and a button. The input is a number only, and when we click "add" ...
1
vote
1
answer
57
views
When a React hook depends on a function that comes itself from a hook, should I memoize it first?
I'm an experienced programmer (10+ years) but new to React (< 2 years). I picked up React in a very "operational" way (i.e. being happy when things work without very deep understanding of ...
-1
votes
1
answer
33
views
React useState: How to Reset Name to "Friends" without Retaining Previous Input
I'm working on a simple React component using useState. It has an h1 tag that displays "Hello {name}", an input field where the user can type their name, and a button that changes the name ...
-1
votes
2
answers
58
views
React useEffect goes in infinite loop while fetching data [duplicate]
I am trying to fetch some data inside my component using useEffect hook and it is going in infinite loop. I am using this react tutorial page and this race conditions page for reference. Here is my ...