Category "use-state"

ReactJS push to state array replaces every exisitng value in array

I want to push an 2d array into the end of a state. But somehow, when i log the state every time it changes with a useEffect, i replaces every existing array wi

Can a React usestate update be nested in another useState functional update?

There are n items the user can vote on. There are two React states: votes is an array of the user's votes on every item. const [votes, setVotes] = useState({});

How to initialize data using map inside useState in ReactJs?

I'm new to React and in the assignment I'm working on, I have to show data in a AG Grid table. For that this is how I'm initializing rowData inside useState(),

useState hook does not update inside setTimeout function

this code must increase the "count" value gradually from 0 to 600. And each time the "count" value changes it must be logged into the console. But instead, I ge

why does this log the old value and not the new value [duplicate]

const [title,setTitle] = useState(""); const titleHandler=e => { setTitle(e.target.value) console.log(title) } Why does this code log

React console.log showing duplicate results in Dev Tools

Why does React show duplicate console.log? I found that to remove StrictMode from index.js. but there was no such problem before and why did I remove StrictMode

useState() undefined in React just after set

I have a problem and I do not undersatnd why the hook return undefined : import React, { useEffect, useState } from 'react'; function App(){ const [globa

How to change image accordingly on Hover/Mouse enter On Any List Item using set State React

Right Side i have list items on left i have picture area i want to change image accordingly when ever i hover list item

How To Solve The React Hook Closure Issue?

import React, { useState} from "react"; import ReactDOM from "react-dom"; function App() { const [count, setCount] = useState(0); function handleAlertCli

Why my nextjs component is rendering twice?

This is a component that render data from firebase storage and make it listed. What the function has to do is set the videos extracted from firebase storage to

Why is localStorage getting cleared whenever I refresh the page?

Like the title says, the localStorage I set registers the changes made to the todoList array and JSON.stringifys it; however, whenever I refresh the page the ar

Images are not displaying in webpage grid from uploaded image folder

I'm trying to make a memory match game using reactjs. I have my components and other files in src folder. index.html,style.css and image folder(img, with all im

Storing React form data in a nested object with useState

I'm building out a form with React, and I want to store the form fields in an object with nested data like this: { name: "Test User", email: "[email protected]

How to manage multiple states in React? [closed]

I have components in my React App, with more than 20 rows with: useState() Is that the correct way or to assign them in a object, is there so

Apollo Client empty context (sometimes?)

So I've run into this weird issue i cannot resolve. My client code was working fine until today. Without any updates to the packages or to the code related to a

Unable to update state while using React Native

I am trying to get to grips with the React hook useState. At the moment I am unable to update the state of my errors object, a little unsure of where I am going

How to update a form's input text state immediately in React using setState()

const [text, setText] = useState(''); const handleTextChange = (e) => { setText(e.target.value); } // Inside a form <input onChange={handleTextChange

useState and if statement causing Error: Too many re-renders. React limits the number of renders to prevent an infinite loop

What I'm attempting to create is a React component which conditionally renders when the value of the prop boxToggle is true, and also returns null when the user

REACT- Uncaught TypeError: Found non-callable @@iterator

In react, I have a component that takes in 2 destructured parameters. One of them is an array called points. However, when attempting to call the Math.max(...po