• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Variable and input variable React

Resolved: Variable and input variable React

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Variable and input variable React

Question:

Why won’t this code which causes a variable called age to increase or decrease according to the pressing of certain buttons. But then it should also allow us see whatever is typed in the text box be displayed outside of it.
App.js
The think the problem may be that useState is used twice
This is from the tutorial https://youtu.be/f55qeKGgB_M?t=4693

Best Answer:

The problem is that you can’t mutate the state in React. So you can’t have it like this:
Instead you should have something like that:
Short explanation is, that React is comparing entities, and if you do this like you have in code, for React there was no change, but if you will provide new object it will recognize the change.
It is really common mistake, you can read more about this issue on this blog post: https://www.joshwcomeau.com/react/common-beginner-mistakes/#mutating-state-2
I generally recommend to follow Josh for React knowledge.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

react-hooks reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: EntityFramework creates/runs migrations using parameterless DataContext instance

24/03/2023

Resolved: Visual Studio 2022 crashes when using breakpoints

24/03/2023

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.