LoginSignup
1
1

More than 3 years have passed since last update.

React Map<K,V>型でループしてコンポーネントを返したい。

Posted at

表記のとおり、Map型でループしてコンポーネントを返したい場合、

function Qiita(props: { chikyuwaMawaruMap: Map<Date, Unit> }) { 
    return (

//NG   Map<>型でループできる方探してたらforEach があったのでreturn returnで返るのかなと憶測で考えていたけどだめでした。Object.entries() する必要があるみたいです。
 return (
    {props.chikyuwaMawaruMap.forEach((value, index) => {
      return(<JikkoWaSarerukedoReturnSarenai />)
    }}
)
//OK
 {Array.from(props.chikyuwaMawaruMap.entries()).map((entry, index) => {
   Return (<SampleComponent />);
 }}


//FYI
 interface Map<K, V> {
     clear(): void;
     delete(key: K): boolean;
     forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
     get(key: K): V | undefined;
     has(key: K): boolean;
     set(key: K, value: V): this;
     readonly size: number;
 }
1
1
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
1
1