Skip to content

Commit

Permalink
chore: 文件调整
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed May 7, 2024
1 parent 8bbf228 commit 66fc49f
Show file tree
Hide file tree
Showing 52 changed files with 862 additions and 304 deletions.
8 changes: 4 additions & 4 deletions public/babel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">

<link rel="canonical" href="http://localhost:1313/babel/" /><link rel="prev" href="http://localhost:1313/commonjs%E5%92%8Cesm/" /><link rel="next" href="http://localhost:1313/node%E5%9F%BA%E7%A1%80/" />
<link rel="canonical" href="http://localhost:1313/babel/" /><link rel="prev" href="http://localhost:1313/node%E7%9A%84%E7%89%B9%E7%82%B9/" /><link rel="next" href="http://localhost:1313/koa%E6%B4%8B%E8%91%B1%E6%A8%A1%E5%9E%8B/" />
<link rel="stylesheet" href="/css/main.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" href="/lib/animate/animate.min.css">
<noscript><link rel="stylesheet" href="/lib/animate/animate.min.css"></noscript><script type="application/ld+json">{"@context": "https://schema.org","@type": "BlogPosting",
"headline": "Babel",
Expand Down Expand Up @@ -3249,9 +3249,9 @@ <h2 id="参考" class="headerLink">
</section>
</div>

<div class="post-nav print:tw-hidden"><a href="/commonjs%E5%92%8Cesm/" class="prev" rel="prev" title="CommonJS和ESM"><svg class="icon"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"/></svg>CommonJS和ESM</a>
<a href="/node%E5%9F%BA%E7%A1%80/" class="next" rel="next" title="Node基础">Node基础<svg class="icon"
<div class="post-nav print:tw-hidden"><a href="/node%E7%9A%84%E7%89%B9%E7%82%B9/" class="prev" rel="prev" title="Node的特点"><svg class="icon"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"/></svg>Node的特点</a>
<a href="/koa%E6%B4%8B%E8%91%B1%E6%A8%A1%E5%9E%8B/" class="next" rel="next" title="Koa洋葱模型">Koa洋葱模型<svg class="icon"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"/></svg></a></div>
</div>
</article></div>
Expand Down
4 changes: 2 additions & 2 deletions public/categories/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</item><item>
<title>Study Notes</title>
<link>http://localhost:1313/categories/study-notes/</link>
<pubDate>Thu, 07 Dec 2023 16:10:47 &#43;0800</pubDate><author>
<pubDate>Fri, 08 Dec 2023 22:10:34 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/categories/study-notes/</guid>
<description><![CDATA[]]></description>
Expand All @@ -28,7 +28,7 @@
</item><item>
<title>React Hooks</title>
<link>http://localhost:1313/categories/react-hooks/</link>
<pubDate>Tue, 25 Jul 2023 11:47:25 &#43;0800</pubDate><author>
<pubDate>Thu, 27 Jul 2023 11:47:25 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/categories/react-hooks/</guid>
<description><![CDATA[]]></description>
Expand Down
12 changes: 12 additions & 0 deletions public/categories/react-hooks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@
</div><main class="main">
<div class="container"><div class="page archive"><h2 class="single-title animate__animated animate__pulse animate__faster"><svg class="icon"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M527.9 224H480v-48c0-26.5-21.5-48-48-48H272l-64-64H48C21.5 64 0 85.5 0 112v288c0 26.5 21.5 48 48 48h400c16.5 0 31.9-8.5 40.7-22.6l79.9-128c20-31.9-3-73.4-40.7-73.4zM48 118c0-3.3 2.7-6 6-6h134.1l64 64H426c3.3 0 6 2.7 6 6v42H152c-16.8 0-32.4 8.8-41.1 23.2L48 351.4zm400 282H72l77.2-128H528z"/></svg>&nbsp;React Hooks</h2><h3 class="group-title">2023</h3><article class="archive-item">
<a href="/react_hooks--usememousecallback/" class="archive-item-link">React hooks--useMemo&amp;useCallback</a>
<span class="archive-item-date">07-27</span>
</article><article class="archive-item">
<a href="/react_hooks--usecontext/" class="archive-item-link">React hooks--useContext</a>
<span class="archive-item-date">07-27</span>
</article><article class="archive-item">
<a href="/react_hooks--useref/" class="archive-item-link">React hooks--useRef</a>
<span class="archive-item-date">07-26</span>
</article><article class="archive-item">
<a href="/react_hooks--useeffectuselayouteffect/" class="archive-item-link">React hooks--useEffect&amp;useLayoutEffect</a>
<span class="archive-item-date">07-25</span>
</article><article class="archive-item">
<a href="/react_hooks--usestateusereducer/" class="archive-item-link">React hooks--useState&amp;useReducer</a>
<span class="archive-item-date">07-25</span>
</article></div></div>
Expand Down
57 changes: 56 additions & 1 deletion public/categories/react-hooks/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link>http://localhost:1313/categories/react-hooks/</link>
<description>React Hooks - 分类 - Hello World</description>
<generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>[email protected] (EricYuan)</managingEditor>
<webMaster>[email protected] (EricYuan)</webMaster><lastBuildDate>Tue, 25 Jul 2023 11:47:25 &#43;0800</lastBuildDate><atom:link href="http://localhost:1313/categories/react-hooks/" rel="self" type="application/rss+xml" /><item>
<webMaster>[email protected] (EricYuan)</webMaster><lastBuildDate>Thu, 27 Jul 2023 11:47:25 &#43;0800</lastBuildDate><atom:link href="http://localhost:1313/categories/react-hooks/" rel="self" type="application/rss+xml" /><item>
<title>React hooks--useState&amp;useReducer</title>
<link>http://localhost:1313/react_hooks--usestateusereducer/</link>
<pubDate>Tue, 25 Jul 2023 11:47:25 &#43;0800</pubDate><author>
Expand All @@ -16,5 +16,60 @@ tsx
const [state, setState] = useState(initialState) 心智模型(重要)在函数组件中所有的状态在一次渲染中实际上都是不变的,是静态的,你所能看到的 setState 引起的渲染其实已经是下一次渲染了。理解这一点尤为重要,感谢 Dan 的文章讲解。
tsx
const [number, setNumber] = useState(0) const plus = () =&gt; { setNumber(number + 1) setNumber(number + 1) setNumber(number + 1) console.log(&#39;plus ---&#39;, number) // 输出仍然为 0, 就像一个快照 } useEffect(() =&gt; { console.log(&#39;effect ---&#39;, number) // 输出为 1,因为setNumber(number + 1) 的number在这次渲染流程中始终都是 0 !!! }, [number]) /* ---------- 如果依赖于前一次的状态那么应该使用函数式写法 ---------- */ const plus = () =&gt; { setNumber((prev) =&gt; prev + 1) // 更新函数 prev 准确的说是pending state setNumber((prev) =&gt; prev + 1) setNumber((prev) =&gt; prev + 1) console.]]></description>
</item><item>
<title>React hooks--useEffect&amp;useLayoutEffect</title>
<link>http://localhost:1313/react_hooks--useeffectuselayouteffect/</link>
<pubDate>Tue, 25 Jul 2023 21:47:25 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/react_hooks--useeffectuselayouteffect/</guid>
<description><![CDATA[useEffectuseEffect(() =&gt; { setup }, dependencies?)
执行时机useEffect 是异步的:
setup 函数在 DOM 被渲染后执行。如果 setup 返回了 cleanup 函数,会先执行 cleanup,再执行 setup。
当组件挂载时都会先调用一次 setup,当组件被卸载时,也会调用一次 cleanup。
值得注意,cleanup 里的状态是上一次的状态,即它被 return 那一刻的状态,因为它是函数嘛,类似快照。
关于 dependencies:
无,每次都会执行 setup [],只会执行一次 setup [dep1,dep2,&hellip;],当有依赖项改变时(依据 Object.is),才会执行 setup 心智模型&ndash;每一次渲染的 everything 都是独立的一个看上去反常的例子:
tsx
// Note: 假设 count 为 0 useEffect( () =&gt; { const id = setInterval(() =&gt; { setCount(count + 1) // 只会触发一次 因为实际上这次渲染的count永远为 0,永远是0+1 }, 1000) return () =&gt; clearInterval(id) }, [] // Never re-runs ) 因此需要把 count 正确的设为依赖,才会触发再次渲染,但是这么做又会导致每次渲染都先 cleanup 再 setup,这显然不是高效的。可以使用类似于 setState 的函数式写法:setCount(c =&gt; c + 1) 即可。这么做是既告诉 React 依赖了哪个值,又不会再次触发 effect 。]]></description>
</item><item>
<title>React hooks--useRef</title>
<link>http://localhost:1313/react_hooks--useref/</link>
<pubDate>Wed, 26 Jul 2023 11:47:25 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/react_hooks--useref/</guid>
<description><![CDATA[useRef const ref = useRef(initialValue)
ref 就是引用,vue 中也有类似的概念,在 react 中 ref 是一个形如 {current: initialValue} 的对象,不仅可以用来操作 DOM,也可以承载数据。
与 useState 的区别既然能承载数据,那么和 useState 有什么渊源呢?让我们看看官网的一句话:useRef is a React Hook that lets you reference a value that’s not needed for rendering.,重点在后半句,大概意思就是引用了一个与渲染无关的值。
在承载数据方面,这就是与 useState 最大的区别:
useRef 引用的数据在改变后不会影响组件渲染,类似于函数组件的一个实例属性 useState 的值改变后会引发重新渲染 函数式组件在每次渲染中的 props、state 等等都是那次渲染中所独有的,当需要在 useEffect 中访问未来的 props/state 时,可以使用 useRef 。Demo: 随意输入并 send 后,再次输入,获取的是全部的输入。
TS 环境下的使用在 TS 环境下,往往你可能会遇到此类报错:
Type '{ ref: RefObject&lt;never&gt;; }' is not assignable to type 'IntrinsicAttributes'.]]></description>
</item><item>
<title>React hooks--useContext</title>
<link>http://localhost:1313/react_hooks--usecontext/</link>
<pubDate>Thu, 27 Jul 2023 11:47:25 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/react_hooks--usecontext/</guid>
<description><![CDATA[ useContextconst value = useContext(SomeContext)
简单理解就是使用传递下来的 context 上下文,这个 hook 不是独立使用的,需要先创建上下文。
createContextconst SomeContext = createContext(defaultValue)
创建的上下文有 Provider 和 Consumer(过时):
tsx
&lt;SomeContext.Provider value={name: &#39;hello world&#39;}&gt; &lt;YourComponent /&gt; &lt;/SomeContext.Provider&gt; // useContext 替代 Consumer const value = useContext(SomeContext) useContext 获取的是离它最近的 Provider 提供的 value 属性,如果没有 Provider 就去读取对应 context 的 defaultValue。
性能优化当 context 发生变化时,会自动触发使用了它的组件重新渲染。因此,当 Provider 的 value 传递的值为对象或函数时,应该使用 useMemo 或 useCallback 将传递的值包裹一下避免整个子树组件的无效渲染(比如在 useEffect 中讲过的:函数在每次渲染中都是新的函数)。
reference createContext useContext ]]></description>
</item><item>
<title>React hooks--useMemo&amp;useCallback</title>
<link>http://localhost:1313/react_hooks--usememousecallback/</link>
<pubDate>Thu, 27 Jul 2023 11:47:25 &#43;0800</pubDate><author>
<name>EricYuan</name>
</author><guid>http://localhost:1313/react_hooks--usememousecallback/</guid>
<description><![CDATA[在之前的笔记中,讲了很多次的心智模型 &ndash; 组件在每次渲染中都是它全新的自己。所以当对象或函数参与到数据流之中时,就需要进行优化处理,来避免不必要的渲染。
useMemoconst cachedValue = useMemo(calculateValue, dependencies)
memoconst MemoizedComponent = memo(SomeComponent, arePropsEqual?)
useMemo 是加在数据上的缓存,而 memo api 是加在组件上的,只有当 props 发生变化时,才会再次渲染。
没有arePropsEqual,默认比较规则就是 Object.is
useCallbackconst cachedFn = useCallback(fn, dependencies)
reference useMemo useCallback ]]></description>
</item></channel>
</rss>
9 changes: 9 additions & 0 deletions public/categories/study-notes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,17 @@
</div><main class="main">
<div class="container"><div class="page archive"><h2 class="single-title animate__animated animate__pulse animate__faster"><svg class="icon"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M527.9 224H480v-48c0-26.5-21.5-48-48-48H272l-64-64H48C21.5 64 0 85.5 0 112v288c0 26.5 21.5 48 48 48h400c16.5 0 31.9-8.5 40.7-22.6l79.9-128c20-31.9-3-73.4-40.7-73.4zM48 118c0-3.3 2.7-6 6-6h134.1l64 64H426c3.3 0 6 2.7 6 6v42H152c-16.8 0-32.4 8.8-41.1 23.2L48 351.4zm400 282H72l77.2-128H528z"/></svg>&nbsp;Study Notes</h2><h3 class="group-title">2023</h3><article class="archive-item">
<a href="/jdbc/" class="archive-item-link">jdbc</a>
<span class="archive-item-date">12-08</span>
</article><article class="archive-item">
<a href="/mysql_3/" class="archive-item-link">Mysql_3_视图和管理</a>
<span class="archive-item-date">12-07</span>
</article><article class="archive-item">
<a href="/mysql_2/" class="archive-item-link">Mysql_2_索引和事务</a>
<span class="archive-item-date">12-07</span>
</article><article class="archive-item">
<a href="/mysql_1/" class="archive-item-link">Mysql_1_基础</a>
<span class="archive-item-date">11-30</span>
</article></div></div>
</main><footer class="footer">
<div class="footer-container"><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2022 - 2024</span><span class="author" itemprop="copyrightHolder">
Expand Down
Loading

0 comments on commit 66fc49f

Please sign in to comment.