Module 02 · Understanding Function Components with Array and DOM Manipulation函数组件、数组与 DOM 操作
Lesson 1 Summary: Introduction to Function Components第 1 课总结:函数组件简介
Congratulations! You have completed this lesson. At this point in the course, you know that:
恭喜!你已经完成了这个课程。在这个课程阶段,你知道:
- Props principles include reusability, unidirectional data flow, customization, and composition.
属性原则包括可重用性、单向数据流、自定义和组合。 - You can use the "useState" hook with an event to control a child component.
您可以使用“useState”钩子与事件来控制子组件。 - You use component composition to combine smaller components to create a complex UI.
您使用组件组合将较小的组件组合起来创建复杂的用户界面。 - Principles of component composition include abstraction, reusability, hierarchy, props and children, and higher-order components.
组件组合原则包括抽象、可复用性、层次结构、props 和 children 以及高阶组件。 - State management allows you to manage data that can change over time within a component.
状态管理允许您管理组件内随时间变化的数据。 - The useState hook enables function components to manage the component's state locally.
useState 钩子使函数组件能够本地管理组件的状态。 - You can use this syntax when using the useState hook:
您可以在使用 useState 钩子时使用此语法:- Call the "useState" function and pass in the initial state as a parameter.
调用 "useState" 函数并传入初始状态作为参数。 - Assign the return value to a const array variable using a destructured array.
将返回值赋给一个 const 数组变量,使用解构数组。 - The array has two values: the state name and the state name prefixed with the keyword "set."
数组包含两个值:状态名称和以关键字 "set" 为前缀的状态名称。
- Call the "useState" function and pass in the initial state as a parameter.
- The mounting phase initializes the component, sets up the initial state, and performs side effects.
组件安装阶段初始化组件,设置初始状态,并执行副作用。 - In the updating phase, React re-invokes the function body and re-evaluates JSX.
在更新阶段,React 重新调用函数体并重新评估 JSX。 - In the unmounting phase, React executes cleanup operations when removing a component from the DOM.
在卸载阶段,React 在从 DOM 中移除组件时执行清理操作。