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

前端 未结 24 1806
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 18:04

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

If I have:



Hi~
this
相关标签:
24条回答
  • 2020-11-28 18:54

    Use:

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

    Result:

    Hi,

    Curtis!

    0 讨论(0)
  • 2020-11-28 18:54

    Use \n in text and css white-space: pre-wrap;

    0 讨论(0)
  • 2020-11-28 18:58

    You can try using like this

    <text>{`${val}\n`}</text>
    
    0 讨论(0)
  • 2020-11-28 19:00

    Just put {'\n'} within the Text tag

    <Text>
    
       Hello {'\n'}
    
       World!
    
    </Text>
    
    0 讨论(0)
  • 2020-11-28 19:02

    Just use {"\n"} where you want to break the line

    0 讨论(0)
  • 2020-11-28 19:02
    <Text>
    Hi~{"\n"}
    this is a test message.
    </Text>
    
    0 讨论(0)
提交回复
热议问题