Skip to content
Advertisement

How to add two states to my component inputText in OnChangeText

I need to add two parameters to my onChangeText, but I don’t know how I can do that,

My component is:

JavaScript

The functions HandleDDD and Handle CelNumber are call where my param phone is true, but i need this change state with my onChangeValue aways, but the way I did, not work

can you help me?

Advertisement

Answer

From on your code, it seems like:

  • you get props value and onChangeValue from this.props
  • the TextInput represents either a phone number or a DDD
  • we know whether it’s a phone number or a DDD based on if this.props includes phone or ddd

Based on those points, I don’t actually think that you need to be storing your input value in the state for this component. This can be a controlled component where you call back to this.props.onChangeValue on every change.

I don’t know what your functions normalizePhone and normalizeDDD are doing. It’s possible that you only want to call back to the parent when you get a value that passes validation. But that is incompatible with what I’m seeing here which is that you are setting the value for the TextInput to this.props.value.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement