LoginSignup
0
0

More than 3 years have passed since last update.

【React.js】flowで型チェックを回避しつつArray型の項目をサーバー側へのPostパラメーターとして設定する方法

Last updated at Posted at 2019-06-04

flowで型定義したReact.jsにて、Array型で定義したstate項目(前提: 中身は数字のみ)をサーバー側へのPostパラメーターとして設定しようとしたら以下のようなエラーメッセージが表示された。

flowの型チェック実行コマンド
npm run flow
表示されたエラーメッセージ
Cannot coerce Array型state項目名 to string because array type [1] should not be coerced.

結論、該当のArray型項目をPostパラメーターに設定する際、JSON.stringifyする事でflowの型チェックエラーに抵触しないようにできた。

Postパラメーター設定イメージ
params += `パラメーター項目名=${パラメーター項目となる変数名}&`;
params += `パラメーター項目名=${JSON.stringify(Array型項目となる変数名)}&`;

意外と、Array型項目をPostパラメーターの項目として設定する際のflowの型チェックエラーの対応方法を探すのに手間取った。。。。

0
0
6

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