Learn Before
Concept
Using State Correctly in React Js
After initialization, we cannot directly change the value of a state, as this will not trigger the re-render method.
this.state.comment = 'Hello'; // <-- Wrong
To correctly change the state value, you need to call the setState function.
this.setState({comment: 'Hello'}); // <-- Correct
0
1
Updated 2023-02-10
Tags
JavaScript Programming Language
Object-Oriented Programming
Programming Language Paradigms
General programming languages
Computing Sciences