LoginSignup
39
13

More than 5 years have passed since last update.

React Nativeで改行したい!やり方3選

Last updated at Posted at 2017-06-30

やり方3種類

  1. テンプレートリテラルを用いる
  2. \nを{}で囲って用いる
  3. コンポーネントを分ける

1. テンプレートリテラルを用いる

<Text>
{`
  1行目
  2行目
`}
</Text>

2. \nを{}で囲って用いる

<Text>1行目{"\n"}2行目</Text>

3. コンポーネントを分ける

<Text>1行目</Text>
<Text>2行目</Text>

実践編

import Text from 'react-native'; 

class Aiueo extends Component {

  render() {
    text = "あい  うえ  お"

    return(
      <Text>
        { text.replace(/\s\s/g, '\n') }
      </Text>
    )
  }
}
あい
うえ
お

他のやり方をご存知の方、コメントお待ちしております〜!

39
13
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
13