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

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

    Another way to insert
    between text lines that are defined in an array:

    import react, { Fragment } from 'react';
    
    const lines = [
      'One line',
      'Another line',
    ];
    
    const textContent =
      lines.reduce(items, line, index) => {
        if (index > 0) {
          items.push(
    ); } items.push({line}); return items; }, []);

    Then the text can be used as variable:

    {textContent}
    

    If not available, Fragment can be defined this way:

    const Fragment = (props) => props.children;
    

提交回复
热议问题