0

How can I insert a line break into a text component in React Native?

I checked here about my problem.
But my case is a little bit different.
So it doesn't work with that way.
This is my container code and it gives props to ContactInfo.

  return data.map( 
    (contact, i) => { 
      return (<ContactInfo contact={contact} key={i} />); 
    } 
  );

This is child component. It recieves props as contact.

      <Text>{this.props.contact.name}</Text>

And finllay, it gives the result 'name'.
I expect

David
John
Wade

But it gives 'DavidJohnWade'.

I can't put {"\n"} and ` into of child component since that is only one line.
How can i solve this?

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51
James Thomas
  • 169
  • 1
  • 3
  • 13

1 Answers1

0

Since you are passing a string, if you pass {"\n"} is just gonna see it as a string. try going the javascript way , use "\n" in your contact.name like "David \n John \n Wade"

RegularGuy
  • 3,516
  • 1
  • 12
  • 29