Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic icon name #321

Open
ejerskov opened this issue Dec 12, 2024 · 2 comments
Open

Dynamic icon name #321

ejerskov opened this issue Dec 12, 2024 · 2 comments

Comments

@ejerskov
Copy link

ejerskov commented Dec 12, 2024

Im trying to use country-icons dynamically based on input, but Im having issues.

<script setup lang="ts">
import { Icon } from '#components'

const props = defineProps<{
  country: string
}>()

const icon = computed(() => {
  const icon = props?.country.toLowerCase()
  if (icon == 'northern ireland') {
    return 'ireland'
  }
  return icon
})
const FlagIcon = h(Icon, { name: 'twemoji:flag-' + icon.value, size: 18 })

</script>
<template>
  <FlagIcon />
</template>

This is working when loading the page SSR, but navigating to the page results in errors like this:
DR5f3n0Z.js:52 [Icon] failed to load icon 'twemoji:flag-hungary'

How can I create the icon names dynamically?

@antfu
Copy link
Member

antfu commented Dec 12, 2024

Can you provide a minimal reproduction? Thanks.

Why reproduction is required

@ejerskov
Copy link
Author

Hi @antfu
Im not very familiar with repos so I hope that this is a generic example where someone can help me on how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants