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.

Reactでaxiosを使ってレスポンスヘッダを取得する

Last updated at Posted at 2023-08-20

やりたかったこと

Reactでaxiosを使ってレスポンスヘッダ内のハイフン付きのvalueを取得する。
ハイフン付きの場合は角かっこで取り出す必要があった。

ダメだった書き方

ng.tsx
axios.post(url, req_body, { headers: headers })
  .then((res) => {
    console.log(res.headers.x-subject-token);
  }

この書き方だとVSCodeのPrettierに怒られて保存時にこのままの形で保存されなかった。

成功した書き方

ok.tsx
axios.post(url, req_body, { headers: headers })
  .then((res) => {
    console.log(res.headers["x-subject-token"]);
  }
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?