4

I am new to react-native. I am doing a simple salary calculator component for practice. I have two TextInput components, but I can't seem to type anything in them. Here is the code for my component:

class SueldoCalc extends Component {
  constructor(props)
  {
     super(props);
  }

 calcSalario()
 {
   console.log("Calculating");
 }

render() 
{
return (
  <View>
      <Text>Entre las horas trabajadas:</Text>
      <TextInput />
      <Text>Entre el rate por hora:</Text>
      <TextInput />
      <TouchableHighlight onPress={this.calcSalario}>
        <Text>Calcular salario...</Text>
      </TouchableHighlight>
  </View>
);

}

}

I tried subscribing to onTextChange events, but nothing. This is so basic, I can't find anything out there. Please help! I am running the app on Android Simulator for Visual Studio.

2 Answers 2

3

I had the same problem both in Android and IOS. After I set width and height as the following (be careful both width and height must be set), the problem solved:

<TextInput style={{ height: 20, width: 100 }} />
Sign up to request clarification or add additional context in comments.

Comments

1

You should specify onTextChange handler then set the state from there. Your <TextInput /> should have a value property:

<TextInput 
    value={this.state.horas}
    onChange={this._onChangeHandler}
/>

4 Comments

Even after adding both properties I still cannot type anything. I did my TextInput like this: <TextInput value={this.state.text} onChangeText={(text)=>{this.setState({text:text})}} />
While the answer is correct, doing this did not solve the problem. I switched from the Android Emulator for Visual Studio to an AVD created with the Android SDK and this solved my problem.
try adding a style={{height: 40}} to your TextInput
Could you have a look at this? onChange doesn't work for me stackoverflow.com/questions/61658623/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.