Grokking React Native
0% completed
Common Mistakes When Using State
Each of the eight mistakes below was run as real code, and the results shown are what came back. Several of them produce no error at all, so knowing the symptom matters as much as knowing the fix. The wording of an error message can differ slightly on a phone.
Mistake 1: Changing State Directly
State is read-only from your code's point of view, and only the setter may change it. With a number, JavaScript blocks the change, because useState is usually unpacked into a const:
const [count, setCount] = useState(0); const increment = () => { count++; };
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%