简体   繁体   English

带有反应的动态离子图标 typescript

[英]dynamic ionic icon with react typescript

I want to make my IonIcons dynamic so they are reusable.我想让我的 IonIcons 动态化,以便它们可以重复使用。 But i need to set it in {} I dont know how i do this with a.map() element.但我需要在 {} 中设置它 我不知道如何使用 a.map() 元素执行此操作。

import React from "react";
import { IonIcon, IonLabel } from "@ionic/react";
import styles from "./quickOptions.module.css";
import { alarmOutline, personOutline, cartOutline } from "ionicons/icons";

export default function quichOptions() {
  const quickOptions = [
    { title: "Jouw consulent", icon: { personOutline } },
    { title: "Jouw afspraken", icon: { alarmOutline } },
    { title: "Jouw bestellingen", icon: { cartOutline } },
  ];

  return (
    <div className={styles.mainContainer}>
      {quickOptions?.map((element: any) => {
        return (
          <div key={element.title} className={styles.btnContainer}>
            <IonLabel>{element.title}</IonLabel>
            <IonIcon icon={element.icon} size="large" /> //here
          </div>
        );
      })}
    </div>
  );
}

Element.icon does not give the output of {personOutline} for example does anybody know how to fix this??例如,Element.icon 没有给出 {personOutline} 的 output 有人知道如何解决这个问题吗?

you can check console.log(typeof element.icon)你可以检查 console.log(typeof element.icon)

const quickOptions = [ { title: "Jouw consulent", icon: 'personOutline' }, ]; const quickOptions = [ { title: "Jouw consulent", icon: 'personOutline' }, ];

<IonIcon icon={element.icon} size="large" />

if the icon type here is {string}, that's why it doesn't work如果这里的图标类型是{string},这就是它不起作用的原因
try it in quickOptions, icon: personOutline or icon: 'personOutline'在 quickOptions 中尝试,图标:personOutline 或图标:'personOutline'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM