React-Native : Space between underline text

367 Views Asked by At

I am using style={{textDecorationLine: 'underline'}}, but app currently shows like this. But I want it to look like this

2

There are 2 best solutions below

0
Nooruddin Lakhani On

Try this way

renderTexts() {
    return textArray.map((item) => {
        return (
            <Text style={{textDecorationLine: 'underline'}}>{item.text}</Text>
        );
    });
}
...

render() {
    return (
        <View style={{flexDirection: 'row'}}>
            { this.renderTexts() }
        </View>
    )
}
0
B. Mohammad On

Here is a tested example on snack based on @Nooruddin Lakhani with some modifications.

the result:

enter image description here

the code:


export default function App() {
  const textArray = ['this', 'is', 'a', 'test'];
  const renderTexts = () => {
    return textArray.map((item) => {
      return (
        <Text style={{ textDecorationLine: 'underline', marginLeft:2 }}>{item}</Text>
      );
    });
  };

  return (
    <View>
      <Text>{renderTexts()}</Text>
    </View>
  );
}