<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Frontend on pemako</title>
    <link>http://pemako.cn/tags/frontend/</link>
    <description>Recent content in Frontend on pemako</description>
    <image>
      <title>pemako</title>
      <url>http://pemako.cn/images/papermod-cover.png</url>
      <link>http://pemako.cn/images/papermod-cover.png</link>
    </image>
    <generator>Hugo -- 0.146.6</generator>
    <language>en</language>
    <lastBuildDate>Thu, 09 Apr 2026 20:00:00 +0800</lastBuildDate>
    <atom:link href="http://pemako.cn/tags/frontend/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>React</title>
      <link>http://pemako.cn/posts/react/</link>
      <pubDate>Thu, 09 Apr 2026 20:00:00 +0800</pubDate>
      <guid>http://pemako.cn/posts/react/</guid>
      <description>&lt;h2 id=&#34;基础知识&#34;&gt;基础知识&lt;/h2&gt;
&lt;h3 id=&#34;props&#34;&gt;&lt;strong&gt;props&lt;/strong&gt;&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;props 是配置组件行为和外观的外部输入，它决定组件渲染什么，但组件不能修改它。&lt;/p&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;props-的三个核心含义&#34;&gt;&lt;strong&gt;props 的三个核心含义&lt;/strong&gt;&lt;/h3&gt;
&lt;h4 id=&#34;1-组件的外部数据输入&#34;&gt;&lt;strong&gt;1. 组件的外部数据输入&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;组件不是凭空渲染，它需要“数据”，而 props 就是数据来源。&lt;/p&gt;
&lt;h4 id=&#34;2-父组件--子组件的数据流单向数据流&#34;&gt;&lt;strong&gt;2. 父组件 → 子组件的数据流（单向数据流）&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;React 明确规定：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;数据只能从父流向子&lt;/li&gt;
&lt;li&gt;子组件不能直接改 props
这个规则保证了 UI 是可预测的。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;3-组件之间的通信方式父传子&#34;&gt;&lt;strong&gt;3. 组件之间的通信方式（父传子）&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;子组件不直接知道父组件是谁，只知道父组件给它的 props。&lt;/p&gt;
&lt;p&gt;在声明 props 时， &lt;strong&gt;不要忘记 &lt;code&gt;(&lt;/code&gt; 和 &lt;code&gt;)&lt;/code&gt; 之间的一对花括号 &lt;code&gt;{&lt;/code&gt; 和 &lt;code&gt;}&lt;/code&gt;&lt;/strong&gt; ：&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;function Avatar({ person, size }) {  

}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;这种语法被称为 &lt;a href=&#34;https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_a_function_parameter&#34;&gt;“解构”&lt;/a&gt;，等价于于从函数参数中读取属性：&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;function Avatar(props) {  
	let person = props.person;  
	let size = props.size;  
	// ...  
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;state&#34;&gt;&lt;strong&gt;state&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;state 是组件&lt;strong&gt;内部可变的&lt;/strong&gt;数据，用来驱动组件的渲染与行为。它由组件自己拥有和管理（或通过 useReducer/外部管理器协调），当 state 变化时 React 会重新渲染该组件（及其子树）。&lt;/p&gt;
&lt;h3 id=&#34;组件&#34;&gt;组件&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;React 允许你创建组件，&lt;strong&gt;应用程序的可复用 UI 元素&lt;/strong&gt;。&lt;/li&gt;
&lt;li&gt;在 React 应用程序中，每一个 UI 模块都是一个组件。&lt;/li&gt;
&lt;li&gt;React 是常规的 JavaScript 函数，除了：
&lt;ol&gt;
&lt;li&gt;它们的名字总是以大写字母开头。&lt;/li&gt;
&lt;li&gt;它们返回 JSX 标签。&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;一个文件里有且仅有一个 &lt;em&gt;默认&lt;/em&gt; 导出，但是可以有任意多个 &lt;em&gt;具名&lt;/em&gt; 导出。&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
