title: How would I replace string in TextInput in react-native
body: <p>I am new to Stackoverflow. I was wondering of how to replace string as I am typing it in TextInput. As I can't (and even if it was possible without root/jailbreak) change the keyboard language of the device, I wanted to change the keycode (unicode) as I type it in. Basically change 'w' to 'އ'. That is the basic Idea.</p>
  
  <p>I have already created a JSON object with some keys which contains what I want. Suppose something like this. <code>json = {"w" = "އ"}</code>. Here is the fullcode of where I have gone so far (Sorry for this being the jankiest code ever):</p>
  
  <pre><code>
  const KeyCodes = { "q": "ް", "w": "އ", "e": "ެ", "r": "ރ", "t": "ތ", "y": "ޔ" };
  
  &lt;TextInput
                      style={styles.nameInput}
                      onChangeText={(nameInput) =&gt; this.setState({nameInput})}
                      value={this.state.nameInput}
                      //Here is where all hell breaks loose
                      onKeyPress={({ nativeEvent }) =&gt; {
                          nativeEvent.key in KeyCodes ? this.setState({ nameInput: KeyCodes.q }) : null
                      }}
                  /&gt;
  
  </code></pre>
  
  <p>The expected behavior is to every time when a user inputs, I want the key value to be taken and checked from the <code>KeyCodes</code> and if that key exists, replace that keys value from the json in to the TextInput. I know it is not a function but this was barely a test and I did not know how to continue from here. Maybe move it in to a function and call that function and so on. What I am stuck at is, How would I replace the value with the <code>KeyCodes</code> actual value in to the state or the InputField in general. Right now it replaces the already existing text. And there is a small delay for replacing hence showing the "w" before being replaced to "އ". So basically to recap, Whatever key I press, the key value will be cross checked with the json object and if it exists, take its value and replace it with the key pressed in to the TextInput. Sorry if this was too long and hope this was enough info. And for anyone wondering, this is "Thaana" which is "Dhivehi" language.</p>