1

this is my first stackoverflow question, please bare with me if I do anyhting wrong. Here goes my question: how do I restrict the number of lines in a textInput using react? I have to say im new to react and dont know if i am doing it wrong. I have searched for this question before asking this one and they recommend to use maxheight. Ive tried it and it doesnt work. this is my code. I am trying to restrict the number of written lines to 4. Currently, a textInput appears but i can write more thatn 4 lines.

import React, { Component } from 'react';
import { TextInput } from 'react-native';

export default class UselessTextInput extends Component {
  constructor(props) {
    super(props);
    this.state = { text: 'Write something' };
  }

  render() {
    return (
      <TextInput
        style={{height: 40, borderColor: 'gray', borderWidth: 1}}
        onChangeText={(text) => this.setState({text})}
        value={this.state.text}
        multiline={true}
        numberOfLines={5}
      />
    );
  }
}

Any type of help is very much appreciated.

jonhdoe420
  • 43
  • 5
  • Tags changed, this question related to React Native TextInput component. There are many repeated questions similar to this: https://stackoverflow.com/questions/43128215/react-native-to-limit-lines-in-textinput – Dennis Vash Oct 03 '21 at 11:28
  • hi @DennisVash I appreciate you responding to my post. I have already checked that post before making this post, and I still cant figure it out. Could you please help me out? – jonhdoe420 Oct 03 '21 at 11:38

0 Answers0