Skip to content

Commit 87f21e0

Browse files
committed
add Setting Default Value
1 parent 291c01f commit 87f21e0

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

_data/navigation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ docs:
114114
children:
115115
- title: "What is Uncontrolled Component?"
116116
url: /what-is-uncontrolled-component
117+
- title: "Setting Default Value"
118+
url: /set-default-value-uncontrolled-component
117119
# - title: "Installation"
118120
# url: /install-create-react-app
119121
# - title: "Structure"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Setting Default Value"
3+
permalink: /set-default-value-uncontrolled-component
4+
excerpt: "Setting Default Value - Learn React"
5+
last_modified_at: 2018-05-23T15:58:49-04:00
6+
---
7+
8+
In the React rendering lifecycle, the value attribute on form elements will override the value in the DOM.
9+
10+
But with an uncontrolled component, to handle this case, you can specify a `defaultValue` attribute instead of value.
11+
12+
For example below, I use `defaultValue` attribute to set default value of `<input>` form element:
13+
14+
<p data-height="265" data-theme-id="0" data-slug-hash="rvgGrm" data-default-tab="js,result" data-user="Bunlong" data-embed-version="2" data-pen-title="rvgGrm" class="codepen">See the Pen <a href="https://codepen.io/Bunlong/pen/rvgGrm/">rvgGrm</a> by Bunlong (<a href="https://codepen.io/Bunlong">@Bunlong</a>) on <a href="https://codepen.io">CodePen</a>.</p>
15+
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
16+
17+
Note:
18+
19+
* `<input type="checkbox">` and `<input type="radio">` support `defaultChecked`.
20+
* `<select>` and `<textarea>` supports `defaultValue`.

_site/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333

34-
<meta property="article:published_time" content="2018-05-24T11:04:15+07:00">
34+
<meta property="article:published_time" content="2018-05-24T13:59:22+07:00">
3535

3636

3737

@@ -660,6 +660,14 @@
660660

661661
<li><a href="/what-is-uncontrolled-component" class="">What is Uncontrolled Component?</a></li>
662662

663+
664+
665+
666+
667+
668+
669+
<li><a href="/set-default-value-uncontrolled-component" class="">Setting Default Value</a></li>
670+
663671
</ul>
664672

665673
</li>

_site/sitemap.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@
189189
<lastmod>2018-05-24T02:58:49+07:00</lastmod>
190190
</url>
191191
<url>
192+
<loc>/set-default-value-uncontrolled-component</loc>
193+
<lastmod>2018-05-24T02:58:49+07:00</lastmod>
194+
</url>
195+
<url>
192196
<loc>/</loc>
193197
</url>
194198
</urlset>

0 commit comments

Comments
 (0)