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学习手册
React Router
|
279
每种颜色都包含一个唯一
ID
。这个
ID
可以用来查找保存在
State
中的特定颜色。比如,
我们可以创建一个
findById
函数,它会根据
id
字段在数组中查找相关的对象:
import { compose } from 'redux'
export const getFirstArrayItem = array => array[0]
export const filterArrayById = (array, id) =>
array.filter(item => item.id === id)
export const findById = compose(
getFirstArrayItem,
filterArrayById
)
findById
函数遵循了第
2
章讨论的函数式编程范式。我们可以看到
findById
方法首先会
根据
ID
对数组进行过滤,然后从已过滤数组中返回找到的第一个元素。我们可以使用
findById
函数根据它们的唯一
ID
在
State
中对颜色对象进行定位。
通过
router
,我们可以通过
URL
获取颜色的
ID
。比如,我们将要用于显示“草坪绿”
的
URL
,其中包含了该颜色的
ID
:
http://localhost:3000/#/58d9caee-6ea6-4d7b-9984-65b145031979
Router
参数允许用户获取它们的参数值。它们可以在路由中使用冒号进行定义。比
如,我们可以获取唯一
id
,然后使用
Route
将它另存为一个名为
id
的参数中:
<Route ...
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