nuxt / nuxt/icon

Dynamic icon name

Open
#321 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

need-repro
Dominant language
TypeScript
Stars
1.2k
Forks
96
Avg merge
8h 12m
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided TypeScript script and the Nuxt Icon component, then reproduce the difference between SSR loading and client-side navigation using the dynamic twemoji:flag- name. Trace the icon loading path for navigation and verify that names such as twemoji:flag-hungary render without a client-side load error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.