import React from "react"
import {GiCard2Spades,GiCard3Spades} from "react-icons/gi"
const x = ["GiCard8Spades","GiCard9Spade"]
const y = x.map(item => <item />) //basically to get <GiCard8Spades /> elements
return(<div>{y}</div>)
我知道我可以立即使用 JSX 專案手動創建陣列,但在這種情況下需要其他方式。
uj5u.com熱心網友回復:
試試這個方法
import React from "react"
import {GiCard2Spades,GiCard3Spades} from "react-icons/gi"
const x = [GiCard8Spades,GiCard9Spade];
return(<div>{x.map(item => item)}</div>)//basically to get <GiCard8Spades /> elements
這樣,您將創建一個 JSX.Elements 陣列,而不是字串陣列
uj5u.com熱心網友回復:
是的,我有點愚蠢,應該使用
import React from "react"
import {GiCard2Spades,GiCard3Spades} from "react-icons/gi"
const x = [GiCard8Spades,GiCard9Spades]
const y = x.map(item => React.createElement(item))
return(<div>{y}</div>)
uj5u.com熱心網友回復:
如果你死心塌地使用字串,你可以試試
import * as Icons from "react-icons/gi"
const x = ["GiCard8Spades","GiCard9Spade"];
return(<div>{x.map((item) => Icons[item])}</div>)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507066.html
標籤:javascript 反应 反应图标
上一篇:為什么我不能從JS中的這個HTML表格計算百分比折扣?
下一篇:基于值的自定義排序資料陣列
