mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
entry on controlled input with value null
This commit is contained in:
committed by
Connor McSheffrey
parent
9ed72b43e8
commit
dd52ef92a8
@@ -0,0 +1,20 @@
|
||||
---
|
||||
id: controlled-input-null-value-tip
|
||||
title: Value of null for controlled input
|
||||
layout: docs
|
||||
permalink: controlled-input-null-value-tip.html
|
||||
---
|
||||
|
||||
With a controlled input component, specifying a `value` prevents the user from changing the input unless you desire so (more info [here](forms.html)).
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
React.renderComponent(<input value="hi" />, mountNode);
|
||||
|
||||
setTimeout(function() {
|
||||
React.renderComponent(<input value={null} />, mountNode);
|
||||
}, 2000);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
id: controlled-input-null-value
|
||||
title: Value of null for controlled input
|
||||
layout: docs
|
||||
permalink: controlled-input-null-value.html
|
||||
---
|
||||
|
||||
### Problem
|
||||
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).
|
||||
|
||||
### Solution
|
||||
You might have accidentally set your `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text be edited.
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
React.renderComponent(<input value="hi" />, mountNode);
|
||||
|
||||
setTimeout(function() {
|
||||
React.renderComponent(<input value={null} />, mountNode);
|
||||
}, 2000);
|
||||
```
|
||||
Reference in New Issue
Block a user