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学习手册
186
|
第
8
章
{ type: "ADD_COOLOR" }
上述拼写错误将会在我们的应用程序中导致一个
bug
。这种错误通常并不会触发任何
警告信息,用户只是不会看到对
State
数据的预期变更。如果用户犯了类似错误,那么
它们是很难察觉的。这时候常数就可以帮上大忙了:
import C from "./constants"
{ type: C.ADD_COLOR }
这种方法声明了相同的
Action
,不过使用了一个
JavaScript
常量来代替字符串。
JavaScript
变量中的拼写错误将会导致浏览器抛出异常。将
Action
定义为常量也使得用
户能够充分利用
IDE
工具的智能提示和代码自动补全功能。当输入常量的首个或者前
两个字母时,
IDE
将会为用户自动补全其余的部分。常量的使用并不是必需的,但是
采用这种编码习惯也不失为一个好的主意。
Action
类型命名规范
Action
类型,比如
ADD_COLOR
或者
RATE_COLOR
,只是字符串,因此从技术的角度
来说,用户可以随意地对一个
Action
进行命名。通常来说,
Action
类型是由大
写字母组成的,并使用下划线代替空格。同时用户还需要明确说明该
Action
的
目的。
Action
的有效载荷数据
Action
是以
JavaScript
语法的形式提供变更某个
State
所需的一系列指令的。大部分
State
变更还需要一些数据。哪些记录应该被移除?某个新记录中应该添加哪些新的信息?
我们将此类数据称为
Action
的有效载荷。比如,当我们分发了一个类似
RATE_COLOR ...
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