Skip to main content
Filter by
Sorted by
Tagged with
-6 votes
0 answers
109 views

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
16k views

I am trying to update the masterSteps variable inside the store, but the store is undefined. That's why it is saying MasterSteps is undefined, but in similar way the setRoute method is working and ...
Best practices
0 votes
3 replies
72 views

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 ...
2 votes
1 answer
65 views

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 ...
1 vote
1 answer
2k views

My app is recipe search. A search form and a submit button, and recipe results i get from API. I have query state variable (declared with useState() ) I try to update it with onSubmit function on ...
0 votes
2 answers
124 views

I'm working on a react project where I'm trying to fetch a GET api using useEffect react hook. But the useEffect doesn't seem to work and it gets skipped and rest everything works. I tried the same ...
4 votes
3 answers
4k views

I wrote custom hook for toggling booleand valuse: import { useState } from 'react'; export function useToggle(initialValue: boolean) { const [value, setValue] = useState<boolean>(...
-3 votes
0 answers
36 views

const onChangeFn = (e,i) => { const data = e.target.value; if(/^\d?$/.test(data)){ let new_Array = [...values] new_Array[i] = data; setValues(...
3 votes
2 answers
14k views

I am trying to create a Pomodoro timer in ReactJS. I am having trouble having the timer to stop it's countdown. PomView.js const PomView = () => { const [timer, setTimer] = useState(1500) // ...
0 votes
1 answer
14k views

For the code I am currently working on, I have a very complicated array filled with objects. The point of this page is to change one property of one object in the array at a time, and as is such, the ...
4 votes
3 answers
14k views

I have a simple <TextInput> in React Native and i want to print some text when value change. Its working after second character entered, but not, when user press just one char. I try using ...
3 votes
1 answer
469 views

I'm new to working with react-relay and graphql. I've taken the initiative to create the custom hook below and I'm wondering if this is the correct way to do it or if it goes against the recommended ...
2 votes
1 answer
3k views

I'm trying to implement the SignaturePad in my react project and I can draw the signature, but I can't access the properties in order to clear it or save it. I get the error below on the lines: ref={...
Best practices
0 votes
2 replies
143 views

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
2 answers
339 views

I want to make a useState snippet. I have this code, but I want to create the first uppercase letter in the variable that is linked to "set". "useState hook": { "prefix&...
5 votes
3 answers
18k views

I am building my React App and suddenly I get the following error: Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the ...
298 votes
6 answers
462k views

Lets say I have some state that is dependent on some other state (eg when A changes I want B to change). Is it appropriate to create a hook that observes A and sets B inside the useEffect hook? ...
0 votes
4 answers
2k views

I want to copy the current window.location.href onClick in the button, even if i set the right state i can not actually copy it, what is my problem? Here the code const [copyHref, setCopyHref] = ...
2 votes
1 answer
172 views

When I put my SignaturePad inside of an ant design component library Modal component, it is not able to generate the base64 image. When the code reaches the trim function in the signaturepad, the ...
8 votes
2 answers
9k views

When trying to use the new useSelector hook (see below example) of react-redux typescript gives an error that the function does not exist: Module '"../../../node_modules/@types/react-redux"' has no ...
3 votes
2 answers
6k views

I've been trying to update the object inside an array that represents a React state, the object should be updated when the value of an input is changed, I could find a way myself to update it, but I'm ...
1 vote
3 answers
10k views

I have this element: <input type="file" id="newFile" onChange={handleFileChange} /> <input type="text" id="newMessage" onChange={handleMessageChange} /&...
0 votes
2 answers
2k views

Imagine I have this array of objects fullList = [ {label: "item A", id="itemA", someBool: true}, {label: "item B", id="itemB", someBool: true}, {label: "item C", id="itemC", someBool: true}, ...
3 votes
2 answers
5k views

I'm currently running into some issues whilst developing a TypeScript React app. Underneath is my current code but it's not behaving like I would want it to behave. So what I would like to achieve is ...
440 votes
21 answers
480k views

In the official docs of React it mentions - If you’re familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and ...
0 votes
0 answers
126 views

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 ...
356 votes
5 answers
540k views

I'm migrating a React with TypeScript project to use hooks features (React v16.7.0-alpha), but I cannot figure out how to set typings of the destructured elements. Here is an example: interface IUser {...
-2 votes
2 answers
133 views

I have unexpected behaviour. The user variable that I declared at the top of my App component is null by default. At the first start or refresh of path=/, useEffect of the App component gets executed ...
4 votes
1 answer
729 views

I'm new to React Native. I made a simple app with the latest version in a functional component. I'm trying to achieve on leftside icon onPress right side scroll to that element and this is two ...
-2 votes
0 answers
18 views

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 ...
5 votes
1 answer
10k views

I have a problem getting clientWidth from useEffect. There is a lazyLoad which loads a page with users. import {Suspense, lazy} from 'react'; const UsersContainer = lazy (() => import ('./ users / ...
5 votes
2 answers
13k views

I recently started learning React, and I learn the useState hook, however I'm struggling to learn the useEffect hook. I've looked at the documentation searched it up and also watched a video about it ...
3 votes
1 answer
92 views

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 ...
20 votes
3 answers
15k views

As far as I've known, functions that defined in a React's functional component are regenerated whenever the component rerenders. Since useCallback can be triggered by specific dependencies, it ...
3 votes
1 answer
94 views

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 ...
807 votes
26 answers
592k views

I am writing code so that before the data is loaded from DB, it will show loading message, and then after it is loaded, render components with the loaded data. To do this, I am using both useState ...
38 votes
7 answers
94k views

I have a prop being passed from a parent component to a child component which changes based on the user's input. I want to trigger a data fetch in the child component when that prop changes before the ...
0 votes
1 answer
9k views

I've been using React Hook with useSelector and useDispatch for a while, mostly it works very well but recently I've experienced some very weird scenario. For example: // parentComponent const ...
113 votes
22 answers
192k views

I was trying React Query and got this at the start of my React app. import React from 'react' import { useQuery } from "react-query"; const fetchPanets = async () => { const ...
1 vote
1 answer
4k views

I'm trying to use react hook form with custom TextInput. Before I was using materials input and everything was working correctly. A found one way that I can achieve it but I'm not satisfied with that. ...
2 votes
2 answers
6k views

Why is my checkbox (Material-UI) not updating? I am using useState, useEffect, alongside with Checkbox from Material-UI. This is especially weird because the {isLiked ? <p>liked</p> : <...
9 votes
1 answer
20k views

I am creating a React component library for a Credit Card Form and the CreditCardForm.tsx looks like this: CreditCardForm.tsx: import React, {useState} from "react"; interface ...
0 votes
2 answers
140 views

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

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 ...
2 votes
1 answer
292 views

Could not find a valid source for what's better for this usecase, so... What't better for listening for browser DOM events and changes? the old fashion useEffect+useState or the new ...
-1 votes
1 answer
342 views

I need to synchronously remove a child from the container. I created a simplified code to show my current solution (Which makes use of normal pattern using useState hook) type ChildProps = { index: ...
2 votes
2 answers
473 views

I was changing a state between renders and logging that value on every time the state changes via useEffect. I noticed my console is showing this error bellow: image of console showing the error. [...
21 votes
4 answers
4k views

I am trying to get the element by id. (It's an example code to reproduce the error) function MyComponent(){ const myId = useId(); useEffect(() => { const myComponentDOMElement = document....

1
2 3 4 5
775