akinncar/react-native-mask-text

Initial value

nab39all opened this issue · 2 comments

Can I use initial values for MaskedTextInput?

Yes, you can use defaultValue prop.

<MaskedTextInput
  mask="AAA-9999"
  defaultValue="abc1234"
  onChangeText={(text, rawText) => {
    console.log(text);
    console.log(rawText);
  }}
  style={styles.input}
/>

I tried using defaultValue to load a dynamic initial value from a state, but the value is not displayed. Only an initial value defined as a string is displayed.
In this case, is it possible to use the initial value from the content of a useState state variable?