LoginSignup
6
3

More than 5 years have passed since last update.

React.js (JSX) で <pre>タグ内の改行が消えてなくなるんだけど?

Posted at

JSX で

<pre>
foo
bar
</pre>

と書くと、レンダリングされる結果は

<pre>foo bar</pre>

となる。

いやいや、pre-formatted text を書きたいんだよ俺は。

幸いにも ES6 (ES2015 っていうのかな? babel です) を使っていたので、次のような方法が使えた。

<pre>
{`
foo
bar
`}
</pre>

これでレンダリング結果は

<pre>
foo
bar
</pre>

となる。

Template string が multi line サポートしてくれてて本当に良かった。

6
3
0

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
6
3