次のように、文字列を連結してオブジェクトを形成しようとしています。
{addInput.inputs.map((input, index) => (
<FormField
key={input}
label="Entreprenuer Name*"
controlId={`entreprenuerName-${index}`}
onChange={e => {
startupFourthStepFormActionHandler({ `entreprenuerName-${index}`: e.target.value });
}}
value={startupFourthStepForm.entreprenuerName}
/>
))}
しかし、私はFailed To Compiled
エラーを受け取り、Property assignment expected
この行にあります:
onChange={e => {
startupFourthStepFormActionHandler({ `entreprenuerName-${index}`: e.target.value })
};
私が欲しいのは、オブジェクトのキーにを追加するindex
ことだけentreprenuerName-
です。
何が足りないのですか?
計算されたオブジェクトキーはでラップする必要があります[]
。これを試して:
startupFourthStepFormActionHandler({ [`entreprenuerName-${index}`]: e.target.value });
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加