React State only updates when setting a useless state variable along with the necessary state variable

State is defined like so: const [items, setItems] = useState([] as CartItemType[]); const [id, setId] = useState(); In this case, id is totally useless. Don’t need it in my …

having n states in react, assuming that n won’t be received in props

How could I have n states in a React component Assuming that the component won’t receive this n value in any props, is something that it will get from a database Using useState will create the state, …

Set initial class variable from axios request in React

When i call this function getQuestions = () => { this.setState({ loading: true }) const { data } = this.props axios .get(data.questions) .then((res) => { …

Why is my setState not working when passed as an argument to a function?

For the function fetchApiAndSetStateForWrongGuesses() I pass it two parameters called randNum and wrongGuess. randNum is just a number but wrongGuess is supposed to be a state. The problem is that …

How to immediatelly update Parent state inside Child components

I’m trying to immediatelly update a parent components’ state so I can properly use it in a Child (nested) component. I will try to give as many details as possible so you an understand. So basically I …

Why my data is flickering between previous and new when state is updated in ReactJS?

I’m working on a SPA with data fetch from the Star Wars API. In the characters tab of the project, the idea is to display the characters per page and you can click next or prev to go to page 2, 3, etc….

setState for react function component not updated my state

I’m setting state for start and end date of checkin and checkout date. I got validDateRange which is an array of valid date and length. Try to set the state of total to the length of array multiply …

How can I conditionally map multiple arrays with if statements after fetching an array of objects? (React)

This is all in Prescriptions.js I am fetching a bunch of prescription drugs from my api. const [drugs, setDrugs] = React.useState([]); useEffect(() => { fetch(‘/api/drugs’) .then(…

I get an Error from React: Maximum update depth exceeded

I wrote my codes and i think everything is right but i get an error from react.js Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside …

How to update nested array in React state?

I am trying to update my state so that a nested array gets emptied but the rest of the state stays the same. My state object looks like: this.state = { data: { type: “…