Questions tagged [react-state]

React State is a built-in React object that is used to contain data within a component. One of its main purposes is to re-render the component whenever the state changes.

Official React State Docs

1169 questions
-1
votes
2 answers

Is this code bad practice for resetting state in React?

I have a votes state that's applied to 4 different objects, but my question is if the reset method is correct or if I should refractor my initialState object so I do not need to repeat myself in the reset method. The incrementor for each object and…
-1
votes
1 answer

react class component state data is not available under map function under render function

I have a class component. on that component, I have a state item called tasks_array. import React, { Component } from 'react' import './App.css'; import Task from './component/task' class App extends Component { constructor(props) { …
subhadip pahari
  • 799
  • 1
  • 7
  • 16
-1
votes
1 answer

My props are valued undefined under ComponentDidMount method in React

Why my values under this.props and this.state are undefined in my componentDidMount method? In other parts of my class component I can access my props and state values correctly. Do I need to pass them separately to somewhere or where have I made…
-1
votes
1 answer

How to make my checkbox to be clicked only once and other are unchecked in React.js

I followed a tutorial and created a form with as many checkboxes to be clicked. But, in another case, I need only one box to be checked. The values of checkboxes are dynamic and you never know, how many checkboxes will be created. But, only one can…
-1
votes
1 answer

React State variables are not updating

I have one child component Listing which will get state variable this.state.loading as prop, it will be used to repull data from the server. along with this state variable, i have two more state variables which controls button properties where it…
-1
votes
1 answer

In React, how do I copy a state property by value?

I'm building a React 16.13 application. I want to copy a property from my state in order to manipulate it and leave the underlying state unchanged. I thought this was the way to do it ... async handleFormSubmit(e) { e.preventDefault(); …
Dave
  • 15,639
  • 133
  • 442
  • 830
-1
votes
2 answers

How to setstate in a loop?

i am getting error at this.setState({ Url: resp.data.Url }); in GETAPI TypeError: Cannot read property 'setState' of undefined.. Please suggest. The GETAPI is basically used to render the data from the API. My use-case is to store all the URLs…
ammy
  • 87
  • 1
  • 2
  • 8
-1
votes
1 answer

update react state using previous data

This is a follow up question to this question: Why calling react setState method doesn't mutate the state immediately? I got a React component with a form which can be used to add items or edit a current item. The form is being saved as a state of…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
-1
votes
1 answer

How to make a conditional function call using setState callback function

The below function logic works, but reading through various posts and SO questions, learned that this should be avoided. So, I'm trying to use callback in setState to reference the previous state. saveOptions function call is dependent on the state…
babybear
  • 804
  • 1
  • 10
  • 24
-1
votes
1 answer

React.js: Should JavaScript date object be treated as props or state?

Probably it's natural that everyone starting with React, experiences confusion between props and state. There is a common distinction that if a component needs to change one of its attributes at some point in time, state should be used, otherwise it…
Linas M.
  • 312
  • 1
  • 3
  • 17
-1
votes
2 answers

How to make Hamburger Icon menu function to work with single click in React.js?

I have been following a coding tutorial of making responsive Navbar from Youtube in Html,CSS and JS. While i really wanted to remake it again in react, the hamburger icon works flawlessly previously when i made it in plain Html, CSS and JS Click…
-1
votes
2 answers

React hooks state

this is my react hooks code react hooks state is not update in something function it is update in useEffect(()=>{...},[count]) but it was not update in getContent i don't know why this state is not update if i print a count, it print right in…
sema0710
  • 25
  • 5
-1
votes
1 answer

Pass state/hook/props from parent component to last child

I have started learning react from just 2 weeks before. I have some doubt, Can I create a shareable state/hook in react.meaning I initialize the state from parent class and can able to access from all the grant child class without passing ? If the…
Sandeep Sudhakaran
  • 1,072
  • 2
  • 9
  • 22
-1
votes
2 answers

Having issues trying to store data using state in React so that it is accessible later

I'm writing a React app to pull specific data from an API done through search (forms), storing it and manipulating it using filters and what not. So far I have pulled the data and displayed it, but I just cannot work out how to store it using state…
SkinnyBetas
  • 461
  • 1
  • 5
  • 27
-1
votes
2 answers

How to use setState outside the class with async

I'm trying to use setState after I did a fetch on an api so I can load it into react. The problem is that it is a async function so I can't use it inside the class itself. How can I still change the state from outside the class itself? I have a…
1 2 3
77
78