目標物
都道府県やその他データとなるselect物をoptionタグでmap配列してくれる物を作ろうとしています。
しかし[object Object]と出てしまい、思うようにデータを参照させる事が出来ず、困っています。
初歩的な質問で申し訳ないのですが、どなたかご回答頂けたら助かります。
##現在のコード内容
data.tsx
1export type definesData = {[key:string]:string}[] 2 3export const Prefs : definesData = [ 4 {key:'hokkaido', name:'北海道', area:'Hokkaido'}, 5 {key:'aomori', name:'青森', area:'Tohoku'}, 6 {key:'akita', name:'秋田', area:'Tohoku'} 7];
Option.tsx
1function listToOption(list:definesData) : JSX.Element[] { 2 return list.map((props:{[key:string]:string}) => 3 <option key={props.key} value={props.keys}>{props.name}</option> 4 ) 5} 6 7export const selectPrefs : JSX.Element[] = listToOption(Prefs);
Error内容
Encountered two children with the same key, [object Object]
. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
回答1件
あなたの回答
tips
プレビュー