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.
Questions tagged [react-state]
1169 questions
-2
votes
3 answers
Storing list with objects in a state for future use in react
I am getting a response like this from my axios response and I want to store the same in a state to pass it further.
Please help me how I store this in a state. I am very new to react.

Anurag Singh
- 1
- 2
-2
votes
1 answer
Is the react keep the old state in the component when rendering web page?
I have a list of items, each item has a state and event handler (I am using the setTimeout to simulate the case.) to update the state.
When I remove item 1 from the list, the state of item 2 becomes "aa0" not "bb" or "N.A".
After the setTimeout…

The KNVB
- 3,588
- 3
- 29
- 54
-2
votes
1 answer
Handle multiple check-box in react native
Well, what I am trying to do is I want to create a Filter-Screen in react-native like those we see in Flipkart, Myntra, or Swiggy. I am successfully able to make it but the thing is the code I have written is way too long because of the number of…

MOHAMMAD SIDDIQUE
- 223
- 2
- 5
- 17
-2
votes
1 answer
How to pass data from Component to form submit in ReactJS?
I have created Dropdown which extends Component. In this I am fetching muliple dropdown values an storing it in const data. I want pass this data from Dropdown Component to another Component in the form of function.
Any help would be really great…

Shruti Upari
- 3
- 3
-2
votes
2 answers
Cannot read property 'state' of undefined although using arrow-syntax
In my example, I am fetching a Product-Object from an API. The Product has ImageIds, referring to Images, which I also fetch from an API after the product is fetched.
class ProductDetails extends Component {
state = {
productId:…

Dyvd
- 57
- 6
-2
votes
1 answer
Why is my object in React showing an undefined Object value?
Here is my React component:
const ChartItem = ({ id, apiUrl }) => {
const [nivoChartData, setNivoChartData] = useState([]);
//
//declare the API call
const apiCallAndConversionForNivoFormat = useCallback(async () => {
try…

jakobarsement
- 139
- 8
-2
votes
1 answer
Update state of cart in real time using Hooks (not class component) in React
I have a react ecommerce app and i'm trying to add items to my cart component. On a product container i can change the state of a product to "addedToCart" in order to add that product to the cart. My issue is the state is only updating when the cart…

Uriel
- 195
- 1
- 2
- 14
-2
votes
1 answer
How to add object into nested state in react?
I'm creating simple comment box where user can reply on comment . I have defined state as follows :
this.state = {
comments: [
{
id: "TKT4321",
message: "abc",
},
…

vaibhav
- 1
- 2
-2
votes
3 answers
How to use function return value as a state in React?
I am learning functional components with React and I have a simple code, which returns 'Nah' when the state value is 0.
The problem is that this doesn't work during render. Why is that?
import React, { useState } from "react";
import { Button } from…

jenny
- 307
- 6
- 12
-2
votes
1 answer
Type Error: Cannot assign to read only property 'backgroundColor' of object '#
I'm using React to create a component that will render a different background depending on its property. However, I don't know how to change its property without collapsing the React frame.
Here's my code:
const inactiveStyle = {
backgroundColor:…

Ha Tran
- 25
- 5
-3
votes
1 answer
Why .then() which is in useEffect is not updating my state
targetMovie is null when it comes to rednering. I couldn't find any solutions. First time having unsolvable problem. Please help!
async function getMovie(id) {
try {
const res = await axios.get(apiEndPoint + "/" + id);
const movies = await…

Ali Ahmadi
- 53
- 1
- 4
-3
votes
1 answer
can I pass props with additional distructured value?
I am trying to get pass values from redux, and can I pass values as props and another destructured value?
my code is like this:
function MyFunction(props, {cityData}) {
console.log(props);
useEffect(() => {
props.fetchCity();
}, []);
…

Alazar-dev
- 94
- 2
- 5
-3
votes
2 answers
Why do I get the error "Unexpected token" for this.state?
I'm trying to make a login form and learn React as well. I'm basing everything on React's official documentation. However when I try to do my stuff and add new user inputs, it doesn't compile.
The code returns an error saying Unexpected token…

Jericho
- 161
- 1
- 9
-3
votes
1 answer
React Hooks - update state with new props
I'm very confused about the new implementations with Hooks.
How can I set State values to the received props, it even not re-rendered when props received.
(which is my desired results)
Here is my code:(I would like to set "amount" value to null…

שגיא שלום
- 7
- 2
- 9