From 7cb64e1655366c5eab2a08aacf52d74361368ea9 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 14 Dec 2015 19:48:35 +0800 Subject: [PATCH] revert TextInput example --- docs/DirectManipulation.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/DirectManipulation.md b/docs/DirectManipulation.md index d37da3b4a9c..a47a39fe2cb 100644 --- a/docs/DirectManipulation.md +++ b/docs/DirectManipulation.md @@ -161,6 +161,37 @@ that call back to the `TouchableOpacity` component. `TouchableHighlight`, in contrast, is backed by a native view and only requires that we implement `setNativeProps`. +## setNativeProps to clear TextInput value + +Another very common use case of `setNativeProps` is to clear the value +of a TextInput. The `controlled` prop of TextInput can sometimes drop +characters when the `bufferDelay` is low and the user types very +quickly. Some developers prefer to skip this prop entirely and instead +use `setNativeProps` to directly manipulate the TextInput value when +necessary. For example, the following code demonstrates clearing the +input when you tap a button: + +```javascript +var App = React.createClass({ + clearText() { + this._textInput.setNativeProps({text: ''}); + }, + + render() { + return ( + + this._textInput = component} + style={styles.textInput} /> + + Clear text + + + ); + } +}); +``` +[Run this example](https://rnplay.org/plays/pOI9bA) + ## Avoiding conflicts with the render function If you update a property that is also managed by the render function,