You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
765 B
25 lines
765 B
12 years ago
|
---
|
||
|
id: controlled-input-null-value
|
||
|
title: Value of null for controlled input
|
||
12 years ago
|
layout: cookbook
|
||
12 years ago
|
permalink: controlled-input-null-value.html
|
||
12 years ago
|
prev: children-prop-type.html
|
||
|
next: componentWillReceiveProps-not-triggered-after-mounting.html
|
||
12 years ago
|
---
|
||
|
|
||
|
### Problem
|
||
12 years ago
|
You specified a `value` parameter for your form input, but the input value can still be modified, contrary to [what you'd expect](/react/docs/cookbook/forms.html).
|
||
12 years ago
|
|
||
|
### Solution
|
||
12 years ago
|
You might have accidentally set `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text becomes editable.
|
||
12 years ago
|
|
||
|
```js
|
||
|
/** @jsx React.DOM */
|
||
|
|
||
|
React.renderComponent(<input value="hi" />, mountNode);
|
||
|
|
||
|
setTimeout(function() {
|
||
|
React.renderComponent(<input value={null} />, mountNode);
|
||
|
}, 2000);
|
||
|
```
|