React Native theorytheory 0/50 · 0%
Components · easy

11. Forms and TextInput

Controlled text input for amounts and addresses.

`TextInput` is controlled the same way as an HTML input: you supply `value` and update it via `onChangeText`. For numeric wallet amounts, `keyboardType="decimal-pad"` improves UX.

import { TextInput } from "react-native";
import { useState } from "react";

function AmountInput() {
  const [amount, setAmount] = useState("");
  return (
    <TextInput
      value={amount}
      onChangeText={setAmount}
      keyboardType="decimal-pad"
      placeholder="0.0"
    />
  );
}

Always validate and sanitize input before parsing it into a number or a wei amount — users can paste arbitrary text, and a bad `parseFloat` on an empty string yields `NaN`.

Check your understanding

  1. 1. What prop updates a controlled TextInput's value?

  2. 2. Which keyboardType suits decimal amounts?

  3. 3. Why validate text before parsing to a number?