Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
React学习手册
by
Alex Banks
,
Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from
React学习手册
120
|
第
6
章
引用
引用(
ref
)这个特性允许
React
组件能够和其子元素交互。引用最常见的用途是和
UI
元素交互,以便收集用户的输入信息。比如
HTML
中
form
表单元素。这些元素已经初
始化渲染完毕,不过用户可以与之交互。当用户执行上述操作时,组件需要响应用户
的操作。
本章接下来将会构建一个应用,帮助用户管理和保存特定的十六进制颜色值。这个颜
色管理器程序允许用户将颜色添加到一个列表中。某个颜色被添加到列表中后,用
户就可以对它评级或者删除。我们将需要一个表单来收集用户提供的新颜色信息。
用户可以在相应字段中输入颜色名称和它的十六进制值。
AddColorForm
组件将会使用
一个文本输入框和一个用于选择十六进制颜色值的按钮来渲染
HTML
元素(参见示例
6-4
)。
示例
6-4
:
AddColorForm
组件
import { Component } from 'react'
class AddColorForm extends Component {
render() {
return (
<form onSubmit={e=>e.preventDefault()}>
<input type="text"
placeholder="color title..." required/>
<input type="color" required/>
<button>ADD</button>
</form>
)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
React快速上手开发
Stoyan Stefanov
流畅的Python
Luciano Ramalho
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
C++程序设计:原理与实践(基础篇)(原书第2版)
本贾尼 斯特劳斯特鲁普
Publisher Resources
ISBN: 9787519814236