i have multi language page in nextjs. i want to change language by clicking dropdown.
const language = [
{
locales: 'fa',
name: 'فارسی',
country_code: 'ir'
},
{
locales: 'en',
name: 'English',
country_code: 'gb'
},
{
locales: 'ar',
name: 'العربیه',
country_code: 'sa'
}
]
let router = useRouter()
return (
<>
<div className="dropdown">
<button className="btn btn-link color-link dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<GlobeIcon />
</button>
<ul className="dropdown-menu">
{router.locales.map((locale) =>(
<>
{language.map((code) =>(
<li key={locale}>
<Link href={router.asPath} locale={locale}>
<span className={`flag-icon flag-icon-${code.country_code} mx-5`}>
<a>
{code.name}
</a>
</span>
</Link>
</li>))}</>
))}
</ul>
</div>
</>
i put a map on another map. now it duplicated 3 times. i should have 3 language but because it duplicated now it shows nine.
i think problem is with my jsx code(map part). i think it's because, first i map router and it gives me three items. second time i map language and it will loop each router another time. because of this it duplicated 9 times. how can i fix it