All Questions
Tagged with state react-hooks
789
questions
0
votes
3
answers
51
views
Reactjs useState not replacing previous state
I have a component that loads all products on component load. The component also has a search functionality that takes user input and querys database for products based on user input. Search results ...
0
votes
1
answer
33
views
How To Manage Or Update State From Lower To Higher Order Component?
I want to update the state of a function component from a lower order component. However, I have been unsuccessful at doing this. Sometimes, React state management confuses me.
In the code sample I ...
0
votes
0
answers
17
views
Update state, object with arrays
I would like to know how I could update this state:
details: {id:{optionA: optionA,
optionB: optionB,
quantity:1
}}
It would be something like this:
details: [{ 1: {optionA: optionA, optionB: optionB, ...
1
vote
1
answer
41
views
React state variable throws error when updated using ++ prefix
I'm Fairly new to React and JS, just exploring the nitty-gritties of the lang.
I'm trying to compare the difference in updating the state variable "counter", using the ++ operator( and by ...
0
votes
0
answers
16
views
How to useReducer with a random state? [duplicate]
I am making a game that has a random state, its a Nextjs/React app, and I'm trying to get generate a random state once the component loads through useEffect, but its being called twice somehow.
I ...
0
votes
1
answer
47
views
How to initialize a state with use reducer so it don't clear on reload in React
I am working on a react shopping e-commerce website and i am using useContext and useReducer to set my cart state but each time i add to cart and reload the page my cart clears and reinitialize
each ...
0
votes
1
answer
47
views
React useState not automatically re-rendering to reflect an updated object in my database [duplicate]
I'm working on my first React project where I'm implementing a shopping cart feature. When a user clicks on a button to increase the quantity of an item in their cart, I update the quantity in the ...
-1
votes
2
answers
65
views
State does not update correctly [duplicate]
Hello i just started developing mobile apps with react native and expo. Im making a simple timer app which is supposed to count down to 0 and you can pause, resume and stop the timer. I am currently ...
0
votes
0
answers
44
views
React - setState keeps causing multiple re-renders
I'm generating a random number that links to an icon in an array.
const icons = [paperIcon, scissorsIcon, rockIcon];
// Selected a random icon
const randomIcon = Math.floor(Math.random() * icons....
0
votes
0
answers
23
views
Input fields and dropzone taking previous state values on api call for file stream in React
I am having two pages one is Update user and second is User profile, the Updae user edits the user in userlist while the User profile edit the current logged in User,
The problem I am encountering is ...
0
votes
1
answer
229
views
How can I get my React component to trigger a fetch when another component is used?
I have a React project.
Initially I was fetching the data I want to display on a component straight from the directory and that was working well.
I have now added an endpoint that returns the data and ...
0
votes
0
answers
1k
views
Component is re-rendering although value in zustand store do not change
I'm trying to implement Zustand into my app to avoid unnecessary re-rerendering and improve the performance of my app. For this I created a testStore:
const useTestStore = create((set) => ({
...
0
votes
1
answer
101
views
This comparison appears to be unintentional because the types 'PlaybackState | { state: undefined; }' and 'State' have no overlap
import React, { useState } from 'react'
import { View, StyleSheet, Pressable} from 'react-native'
import TrackPlayer, { State , usePlaybackState } from 'react-native-track-player';
import Icon from '...
0
votes
0
answers
51
views
How to get and use the latest context value in context's function using React functional component
I have this small React application. I am using the power of context.
On clicking on the list item, I want to update the context value's state and call one of the context functions with the latest ...
0
votes
2
answers
69
views
Unable to get latest value from React State
This is my React Component. and when I enter total 6 digits in Otp Input; the onComplete method is getting invoked which will trigger handleSubmit function and It should print the latest value of ...