diff --git a/就业篇/02. 第二章/2-24. Update/Update.md b/就业篇/02. 第二章/2-24. Update/课件资料/Update.md similarity index 100% rename from 就业篇/02. 第二章/2-24. Update/Update.md rename to 就业篇/02. 第二章/2-24. Update/课件资料/Update.md diff --git a/就业篇/02. 第二章/2-24. Update/课堂代码/App.js b/就业篇/02. 第二章/2-24. Update/课堂代码/App.js new file mode 100644 index 0000000..e4e3d0d --- /dev/null +++ b/就业篇/02. 第二章/2-24. Update/课堂代码/App.js @@ -0,0 +1,68 @@ +// 示例一 + +// import React, { useState } from "react"; + +// // 该组件的渲染是非常耗时的 +// function ExpensiveCom() { +// const now = performance.now(); +// while (performance.now() - now < 200) {} +// return

耗时的组件

; +// } + +// function Input() { +// // 维护了一组数据 +// const [num, updateNum] = useState(0); + +// return ( +// <> +// updateNum(e.target.value)} /> +//

num is {num}

+// +// ); +// } + +// function App() { +// return ( +// <> +// +// +// +// ); +// } + +// export default App; + +// 示例二 + +import React, { useState } from "react"; + +function ExpensiveCom() { + const now = performance.now(); + while (performance.now() - now < 200) {} + return

耗时的组件

; +} + +function Counter({ children }) { + const [num, updateNum] = useState(0); + return ( +
+ updateNum(e.target.value)} /> +

num is {num}

+ {children} +
+ ); +} + +function App() { + // 在这个示例中,数据重新又在 App 组件中进行维护了 + // 而且还不像上面的例子那样可以分离出去 + // const [num, updateNum] = useState(0); + + return ( + + + + ); +} + +export default App;