@samitouri / QOS-React-2 / commits / dd52ef92a8

entry on controlled input with `value` null

Cheng Lou committed Oct 2, 2013 at 00:03 UTC dd52ef92a881c8abb1b004699c9247caff08b27e
2 files changed +42
docs/cookbook/cb-08-controlled-input-null-value tip.md new
+20
@@ -0,0 +1,20 @@
1 +---
2 +id: controlled-input-null-value-tip
3 +title: Value of null for controlled input
4 +layout: docs
5 +permalink: controlled-input-null-value-tip.html
6 +---
7 +
8 +With a controlled input component, specifying a `value` prevents the user from changing the input unless you desire so (more info [here](forms.html)).
9 +
10 +You might have ran into a problem where you specified a `value` but the input can still be changed. In this case, you might have accidentally set your `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text be edited.
11 +
12 +```js
13 +/** @jsx React.DOM */
14 +
15 +React.renderComponent(<input value="hi" />, mountNode);
16 +
17 +setTimeout(function() {
18 + React.renderComponent(<input value={null} />, mountNode);
19 +}, 2000);
20 +```
docs/cookbook/cb-08-controlled-input-null-value.md new
+22
@@ -0,0 +1,22 @@
1 +---
2 +id: controlled-input-null-value
3 +title: Value of null for controlled input
4 +layout: docs
5 +permalink: controlled-input-null-value.html
6 +---
7 +
8 +### Problem
9 +You specified a `value` parameter for your form input, but the input value can still be modified, contrary to [what you'd expect](forms.html).
10 +
11 +### Solution
12 +You might have accidentally set your `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text be edited.
13 +
14 +```js
15 +/** @jsx React.DOM */
16 +
17 +React.renderComponent(<input value="hi" />, mountNode);
18 +
19 +setTimeout(function() {
20 + React.renderComponent(<input value={null} />, mountNode);
21 +}, 2000);
22 +```