If you have learned In What is two-way data bindingTwo-way binding between data models and views. When the data changes, the view also changes, and when the view changes, the data also changes synchronously; it can be said that the user's modifications to the view are automatically synchronized to the data model, and the data model also changes in the same way. Advantages of two-way data binding: There is no need to perform CRUD (Create, Retrieve, Update, Delete) operations like one-way data binding. Two-way data binding is most commonly used on forms. In this way, when the user completes the input on the front-end page, we have obtained the user's input data and put it into the data model without any operation. Implementing two-way data binding However, there is no two-way data binding mechanism in Data Impact View In fact, Code import React, { Component } from 'react'; // Import antd UI libraryimport { Button } from 'antd'; class Home extends Component { constructor(props) { super(props); this.state = { inputVal:'', }; } setValue=()=>{ this.setState({ inputVal: "Modify Value" }) } render() { return ( <div className="home" > Home component<p> {this.state.inputVal}</p> {/* Using antd UI library*/} <Button type="primary" onClick={this.setValue}>Modify data</Button> </div> ); } } export default Home; Effect Views affect data Code import React, { Component } from 'react'; import { Button } from 'antd'; // antd UI library class Home extends Component { constructor(props) { super(props); this.state = { inputVal:'', }; } change = (ev)=>{ this.setState({ inputVal:ev.target.value }) } render() { return ( <div className="home" > Home component <input onChange={this.change} // value={this.state.inputVal} defaultValue={this.state.inputVal} placeholder="Enter text content" /> <p> {this.state.inputVal}</p> </div> ); } } export default Home; Effect Notice: When using This concludes this article on the principle of React two-way data binding. For more relevant React two-way binding content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed steps for installing and using vmware esxi6.5
>>: How to rename the table in MySQL and what to pay attention to
This article shares the specific code of js to ac...
Introduction MySQL should be a very common databa...
1. Two properties of table reset: ①border-collaps...
We may have a question: After we install MySQL lo...
Table of contents 1. Install Docker 2. Create a c...
Table of contents background 1. The query conditi...
The Nginx ngx_http_image_filter_module module (ng...
I just started learning about databases recently....
Searching online for methods to deploy Angular pr...
1. Add users and groups 1. Add mysql user group #...
1. View the renderings Select forward: Select bac...
What is WSL Quoting a passage from Baidu Encyclop...
This article example shares the specific code of ...
Tables once played a very important role in web p...
This article shares the specific code for WeChat ...