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

前端 未结 24 1813
佛祖请我去吃肉
佛祖请我去吃肉 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:47

    There are two options:

    Option 1: Using Template Literals.

    const Message = 'This is a message';
    
    
    {`
      Hi~
      ${Message}
    `}
    
    

    Result:

    Hi~
    This is a message
    

    Option 2: Use {'\n'} as line breaks.

    
    
       Hello {'\n'}
    
       World!
    
    
    

    Result:

    Hello
    World!
    

提交回复
热议问题