0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

firebaseで改行したテキストフィールドを登録する

Posted at

目的

  • 改行コードを処理して。。。という必要があるかと思っていたら、ほぼ何もしなくても実現できた
  • この方法について検索して情報を見つけることができなかったため、残す

サンプル

  • 入力側
          <TextField
            id="filled-multiline-flexible"
            fullWidth
            label="本文"
            onChange={(e) => setdiscription(() => e.target.value)}
            multiline
            maxRows={20}
            variant="standard"
            placeholder=""
            value={discription}
            error={discription == ""}
            helperText={discription == "" && "本文が未入力です"}
            sx={{ marginTop: 1 }}
          />

以下の部分で複数行を設定可能にする

            multiline
            maxRows={20}
            variant="standard"

このインプットで cloud storeへ登録すると、次のように登録される。一見、改行コードが飛んでしまったように見えるが、改行コードは入っている
スクリーンショット 2024-02-21 19.03.52.png

  • 出力側
<div style={{ whiteSpace: 'pre-line' }}>
    {firebaseから取得した項目}
</div>

  • 特に改行コードをいじる等の処理はなし

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?