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

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

I want to insert a new line (like \r\n,
) in a Text component in React Native.
If I have:

Hi~

this is a test message.

Then React Native renders Hi~ this is a test message.
Is it possible render text to add a new line like so:
Hi~
this is a test message.

Solutions/Answers:

Solution 1:

I cannot test it right now but this should do it:

<Text>
Hi~{"\n"}
this is a test message.
</Text>

Solution 2:

You can also do:

<Text>{`
Hi~
this is a test message.
`}</Text>

Easier in my opinion, because you don’t have to insert stuff within the string; just wrap it once and it keeps all your line-breaks.

Solution 3:

Use:

<Text>{`Hi,\nCurtis!`}</Text>

Result:

Hi,

Curtis!

Solution 4:

This worked for me

<Text>{`Hi~\nthis is a test message.`}</Text>

(react-native 0.41.0)

Solution 5:

If at all you are displaying data from state variables, use this.

<Text>{this.state.user.bio.replace('<br/>', '\n')}</Text>

Solution 6:

You can use {'\n'} as line breaks.

Hi~ {‘\n’} this is a test message.

Related:  Passing Python Data to JavaScript via Django