{"id":3540,"date":"2021-07-24T08:53:39","date_gmt":"2021-07-24T08:53:39","guid":{"rendered":"http:\/\/the-codest.localhost\/blog\/react-keys-yes-you-need-them-but-why-exactly\/"},"modified":"2026-04-24T11:30:22","modified_gmt":"2026-04-24T11:30:22","slug":"react-lyklar-ja-thu-tharft-tha-en-af-hverju-nakvaemlega","status":"publish","type":"post","link":"https:\/\/thecodest.co\/is\/blog\/react-keys-yes-you-need-them-but-why-exactly\/","title":{"rendered":"React Lyklar, j\u00e1! \u00de\u00fa \u00fearft \u00fe\u00e1, en af hverju n\u00e1kv\u00e6mlega?"},"content":{"rendered":"<p>\u00dea\u00f0 er l\u00edka eitt fleira sem \u00fe\u00fa \u00fearft a\u00f0 muna um og \u00fea\u00f0 er <strong><a href=\"https:\/\/thecodest.co\/is\/blog\/conditional-component-visibility-in-react\/\">React<\/a> Lykill<\/strong> Eiginleiki, hvert atri\u00f0i \u00ed birtu listanum ver\u00f0ur a\u00f0 hafa hann. \u00deetta hugtak er eitt af fyrstu hlutunum sem hver front-end <a href=\"https:\/\/thecodest.co\/is\/blog\/hire-vue-js-developers\/\">\u00fer\u00f3unara\u00f0ili<\/a> kynnist <strong>React<\/strong> \u00cd upphafi fer\u00f0ar \u00feeirra. N\u00fa skulum vi\u00f0 kafa a\u00f0eins d\u00fdpra til a\u00f0 kanna hvers vegna \u00feetta er svona og hven\u00e6r vi\u00f0 getum teki\u00f0 nokkra stuttlei\u00f0ir.<\/p>\n<h2>Af hverju \u00feurfum vi\u00f0 \u00feessa lykilatri\u00f0i?<\/h2>\n<p>Einfaldasta svari\u00f0 h\u00e9r v\u00e6ri \u201ca\u00f0 h\u00e1marka endurteikningar\u201d, en hi\u00f0 fullkomnara svar \u00fearf a\u00f0 minnsta kosti a\u00f0 nefna hugtaki\u00f0 <strong>React Samr\u00e6ming<\/strong>. \u00deetta er ferli\u00f0 vi\u00f0 a\u00f0 komast a\u00f0 \u00fev\u00ed hvernig \u00e1 a\u00f0 uppf\u00e6ra notendavi\u00f0m\u00f3ti\u00f0 \u00e1 sem skilvirkastan h\u00e1tt. Til a\u00f0 gera \u00fea\u00f0 hratt, <strong>React<\/strong> \u00fearf a\u00f0 \u00e1kve\u00f0a hva\u00f0a hlutar \u00ed tr\u00e9 \u00fe\u00e1ttanna \u00feurfa a\u00f0 vera uppf\u00e6r\u00f0ir og hva\u00f0a ekki. M\u00e1li\u00f0 er a\u00f0 \u00fea\u00f0 geta veri\u00f0 margir \u00fe\u00e6ttir \u00ed DOM-inu og \u00fea\u00f0 er nokku\u00f0 kostna\u00f0arsamt a\u00f0 bera saman hvern og einn \u00feeirra til a\u00f0 \u00e1kve\u00f0a hva\u00f0a eigi a\u00f0 uppf\u00e6ra. Til a\u00f0 hagr\u00e6\u00f0a \u00feessu, <strong>React<\/strong> Innlei\u00f0ir diffing-algor\u00edtmann sem byggir \u00e1 tveimur forsendum:<\/p>\n<ol>\n<li>Tv\u00f6 mismunandi ger\u00f0ir af \u00fe\u00e1ttum ver\u00f0a aldrei eins \u2013 endurskipulegg\u00f0u \u00fe\u00e6r.<\/li>\n<li>Forritarar geta handvirkt a\u00f0sto\u00f0a\u00f0 vi\u00f0 a\u00f0 hagr\u00e6\u00f0a \u00feessu ferli me\u00f0 lykilatri\u00f0um, svo a\u00f0 \u00fe\u00e6ttirnir, jafnvel \u00fe\u00f3 r\u00f6\u00f0 \u00feeirra hafi breyst, megi sta\u00f0f\u00e6ra og bera saman hra\u00f0ar.<\/li>\n<\/ol>\n<p>\u00c1 grundvelli \u00feess getum vi\u00f0 dregi\u00f0 \u00fe\u00e1 \u00e1lyktun a\u00f0 hver <strong>React lykill<\/strong> \u00c6tti einnig a\u00f0 vera einstakt (innan lista yfir \u00fe\u00e6tti, ekki al\u00fej\u00f3\u00f0lega) og st\u00f6\u00f0ugt (ekki breytast). En hva\u00f0 g\u00e6ti gerst \u00feegar \u00feau eru ekki \u00feannig?<\/p>\n<h2>Einst\u00e6\u00f0ni, st\u00f6\u00f0ugleiki og fylkisv\u00edsitala<\/h2>\n<p>Eins og vi\u00f0 nefndum \u00e1\u00f0ur, <strong>React lyklar<\/strong> \u00c1 a\u00f0 vera st\u00f6\u00f0ugt og einstakt. Einfaldasta lei\u00f0in til a\u00f0 n\u00e1 \u00feessu er a\u00f0 nota einstakt au\u00f0kenni (til d\u00e6mis \u00far gagnagrunni) og senda \u00fea\u00f0 til hvers \u00fe\u00e1ttar \u00feegar fylki er kortlagt, au\u00f0velt. En hva\u00f0 me\u00f0 a\u00f0st\u00e6\u00f0ur \u00feegar vi\u00f0 h\u00f6fum hvorki au\u00f0kenni, nafn n\u00e9 \u00f6nnur einst\u00f6k au\u00f0kenni til a\u00f0 senda til hvers \u00fe\u00e1ttar? J\u00e6ja, ef vi\u00f0 sendum ekkert sem lykil, <strong>React<\/strong> mun taka n\u00faverandi fylkisv\u00edsit\u00f6lu sem sj\u00e1lfgefi\u00f0 gildi (\u00fear sem h\u00fan er einst\u00f6k innan \u00feess lista) til a\u00f0 me\u00f0h\u00f6ndla \u00fea\u00f0 fyrir <a href=\"https:\/\/thecodest.co\/is\/blog\/why-us-companies-are-opting-for-polish-developers\/\">okkur<\/a>, en \u00fea\u00f0 mun einnig gefa okkur fallega villutilkynningu \u00ed console-inu:<\/p>\n<p><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/fWmP92MWlEdiEo-qINf6WxkfB9ruVrgPnGBCQQwRjm4L2ZplXm72UmL-ChyoXxMbXTuSCkhYGIstU7l6EhT8vSeOrcyuaAqqPn4eYTYp8nXKqqIX5Q72T3Eh93Dg33WWQz9ciCws0.png\" alt=\"\" \/><\/p>\n<p>Af hverju er \u00fea\u00f0 svona? Svari\u00f0 er a\u00f0 fylki-v\u00edsitalan er ekki st\u00f6\u00f0ug. Ef r\u00f6\u00f0 atri\u00f0a breytist, munu allir lyklarnir breytast og vi\u00f0 eigum \u00ed vandr\u00e6\u00f0um. Ef <strong>React<\/strong> \u00deegar forriti\u00f0 lendir \u00ed a\u00f0 r\u00f6\u00f0 \u00fe\u00e1ttanna \u00ed lista hafi breyst mun \u00fea\u00f0 samt reyna a\u00f0 bera \u00fe\u00e1 saman me\u00f0 lykla, sem \u00fe\u00fd\u00f0ir a\u00f0 hver samanbur\u00f0ur endar \u00ed \u00fev\u00ed a\u00f0 endurbyggja einingu og aflei\u00f0ingin er s\u00fa a\u00f0 allur listinn ver\u00f0ur endurbygg\u00f0ur fr\u00e1 grunni. Auk \u00feess getum vi\u00f0 lent \u00ed \u00f3v\u00e6ntum vandam\u00e1lum, eins og uppf\u00e6rslum \u00e1 \u00e1standi eininga fyrir \u00fe\u00e6tti eins og \u00f3st\u00fdr\u00f0um innsl\u00e1ttum og \u00f6\u00f0rum t\u00f6frandi, erfi\u00f0um villuleitavandam\u00e1lum.<\/p>\n<h2>Undantekningar<\/h2>\n<p>Sko\u00f0um aftur fylkisv\u00edsit\u00f6luna. Ef h\u00fan er notu\u00f0 sem <strong>React lykill<\/strong> getur veri\u00f0 svo vandam\u00e1l, af hverju <strong>React<\/strong> Mun \u00fea\u00f0 vera nota\u00f0 sem sj\u00e1lfgefi\u00f0? Er til einhver notkunartilvik \u00fear sem \u00fea\u00f0 er \u00ed lagi a\u00f0 gera \u00fea\u00f0? Svari\u00f0 er j\u00e1, notkunartilvik \u00feess er fastar listar. Ef \u00fe\u00fa ert viss um a\u00f0 listinn sem \u00fe\u00fa birtir muni aldrei breyta r\u00f6\u00f0 sinni, er \u00f6ruggt a\u00f0 nota fylkisv\u00edsit\u00f6lu, en mundu a\u00f0 ef \u00fe\u00fa hefur einst\u00f6k au\u00f0kenni er samt betra a\u00f0 nota \u00feau \u00ed sta\u00f0inn. \u00de\u00fa getur einnig teki\u00f0 eftir \u00fev\u00ed a\u00f0 \u00fea\u00f0 a\u00f0 senda v\u00edsit\u00f6lur sem lykla mun gera <strong>React<\/strong> villubo\u00f0 hverfur, \u00e1 sama t\u00edma og kveikir \u00ed sumum ytri linterum til a\u00f0 birta villu e\u00f0a vi\u00f0v\u00f6run. \u00deetta er vegna \u00feess a\u00f0 bein notkun v\u00edsitala sem lykla er talin sl\u00e6m vinnubr\u00f6g\u00f0 og sumir linterar g\u00e6tu flokka\u00f0 \u00fea\u00f0 sem villu, \u00e1 me\u00f0an <strong>React<\/strong> sj\u00e1lft telur \u00fea\u00f0 vera \u201c\u00fer\u00f3unara\u00f0ilar vita hva\u00f0 \u00feeir eru a\u00f0 gera\u201d a\u00f0st\u00e6\u00f0ur \u2013 svo ger\u00f0u \u00fea\u00f0 ekki nema \u00fe\u00fa vitir virkilega hva\u00f0 \u00fe\u00fa ert a\u00f0 gera. Nokkur d\u00e6mi um \u00feegar \u00fea\u00f0 getur veri\u00f0 \u00ed lagi a\u00f0 nota \u00feessa undantekningu v\u00e6ru fellivalmynd me\u00f0 f\u00f6stum lista af hn\u00f6ppum e\u00f0a birta lista yfir atri\u00f0i me\u00f0 heimilisfangi fyrirt\u00e6kisins.<\/p>\n<h2>Valkostur vi\u00f0 lykil bygg\u00f0an \u00e1 gagnasafni<\/h2>\n<p>Segjum sem svo a\u00f0 ekkert af ofangreindu s\u00e9 valkostur fyrir okkur. Til d\u00e6mis \u00feurfum vi\u00f0 a\u00f0 birta lista yfir \u00fe\u00e6tti bygg\u00f0an \u00e1 strengjara\u00f0 sem m\u00e1 afrita, en einnig m\u00e1 ra\u00f0a upp \u00e1 n\u00fdtt. \u00cd \u00feessu tilfelli getum vi\u00f0 ekki nota\u00f0 neinn af strengjunum \u00fev\u00ed \u00feeir eru ekki einstakir (\u00feetta getur l\u00edka valdi\u00f0 t\u00f6fravillum), og fylki-v\u00edsitalan dugar ekki \u00fear sem vi\u00f0 munum breyta r\u00f6\u00f0inni \u00e1 \u00fe\u00e1ttunum. S\u00ed\u00f0asta \u00farr\u00e6\u00f0i\u00f0 sem vi\u00f0 getum treyst \u00e1 \u00ed svona a\u00f0st\u00e6\u00f0um er a\u00f0 nota einhverjar ytri au\u00f0kenningar. Mundu a\u00f0 \u00fe\u00e6r ver\u00f0a a\u00f0 vera st\u00f6\u00f0ugar, svo vi\u00f0 getum ekki bara nota\u00f0 Math.random(). \u00dea\u00f0 eru nokkur NPM-pakk\u00ed sem vi\u00f0 getum nota\u00f0 \u00ed sl\u00edkum tilvikum, til d\u00e6mis the <a href=\"https:\/\/www.npmjs.com\/package\/uuid\" rel=\"nofollow\">\u201cuuid\u201d<\/a> pakki. Verkf\u00e6ri eins og \u00feetta geta hj\u00e1lpa\u00f0 okkur a\u00f0 halda lykla listans st\u00f6\u00f0ugum og einst\u00f6kum, jafnvel \u00feegar vi\u00f0 finnum ekki vi\u00f0eigandi au\u00f0kenni innan okkar <a href=\"https:\/\/thecodest.co\/is\/blog\/app-data-collection-security-risks-value-and-types-explored\/\">g\u00f6gn<\/a> set. Vi\u00f0 \u00e6ttum fyrst a\u00f0 \u00edhuga a\u00f0 nota gagnagrunnsau\u00f0kenni og fylkisv\u00edsit\u00f6lu (ef m\u00f6gulegt er), til a\u00f0 l\u00e1gmarka fj\u00f6lda pakka sem notu\u00f0 eru af okkar <a href=\"https:\/\/thecodest.co\/is\/dictionary\/why-do-projects-fail\/\">verkefni<\/a>.<\/p>\n<h2>Til a\u00f0 lj\u00faka \u00feessu<\/h2>\n<ul>\n<li>Hvert atri\u00f0i \u00e1 listanum yfir <strong>React<\/strong> \u00de\u00e6ttir skulu hafa einstakt, st\u00f6\u00f0ugt lykilatri\u00f0i,<\/li>\n<li><strong>React lyklar<\/strong> eru notu\u00f0 til a\u00f0 fl\u00fdta fyrir <strong>F\u00e1 samr\u00e6mi \u00ed ferli<\/strong> og for\u00f0ast \u00f3\u00fearfa endurbyggingu \u00fe\u00e1tta \u00e1 listunum,<\/li>\n<li>Besti uppspretta fyrir lykla er einstakt au\u00f0kenni \u00far gagnainnsl\u00e6tti (til d\u00e6mis \u00far gagnagrunninum),<\/li>\n<li>\u00de\u00fa getur nota\u00f0 fylkisv\u00edsit\u00f6lu sem lykil, en a\u00f0eins fyrir kyrrst\u00e6\u00f0a fylkislista \u00fear sem r\u00f6\u00f0in mun ekki breytast.,<\/li>\n<li>Ef engin \u00f6nnur lei\u00f0 er til a\u00f0 f\u00e1 st\u00f6\u00f0ugar og einstakar lyklar, \u00edhuga\u00f0u a\u00f0 nota einhverja utana\u00f0komandi au\u00f0kenningara\u00f0ila, til d\u00e6mis \u201cuuid\u201d-pakkann.<\/li>\n<\/ul>\n<p><article-inline-code-review><\/article-inline-code-review><\/p>\n<p><b>Lesa meira:<\/b><\/p>\n<p><a href=\"https:\/\/thecodest.co\/blog\/why-you-should-probably-use-typescript\">Af hverju \u00fe\u00fa \u00e6ttir (l\u00edklega) a\u00f0 nota TypeScript<\/a><\/p>\n<p><a href=\"https:\/\/thecodest.co\/blog\/how-not-to-kill-a-project-with-bad-coding-practices\/\">Hvernig \u00e1 ekki a\u00f0 drepa verkefni me\u00f0 sl\u00e6mum forritunarvenjum?<\/a><\/p>\n<p><a href=\"https:\/\/thecodest.co\/blog\/data-fetching-strategies-in-nextjs\/\">Stefnur vi\u00f0 gagnaleit \u00ed NextJS<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>A\u00f0 umbreyta fylki \u00ed lista yfir \u00fe\u00e6tti me\u00f0 React er nokku\u00f0 einfalt; \u00ed grundvallaratri\u00f0um \u00fearftu bara a\u00f0 kortleggja fylki\u00f0 og skila r\u00e9ttum \u00fe\u00e6tti fyrir hvern fylki\u00fe\u00e1tt.<\/p>","protected":false},"author":2,"featured_media":3541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3540","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>React Keys, Yes! You Need Them, but Why Exactly? - The Codest<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thecodest.co\/is\/blogg\/react-lyklar-ja-thu-tharft-tha-en-af-hverju-nakvaemlega\/\" \/>\n<meta property=\"og:locale\" content=\"is_IS\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Keys, Yes! You Need Them, but Why Exactly?\" \/>\n<meta property=\"og:description\" content=\"Transforming an array into a list of elements with React is pretty straightforward, basically all you need to do is map that array and return the proper element for every array item.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thecodest.co\/is\/blogg\/react-lyklar-ja-thu-tharft-tha-en-af-hverju-nakvaemlega\/\" \/>\n<meta property=\"og:site_name\" content=\"The Codest\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-24T08:53:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T11:30:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"thecodest\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"thecodest\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/\"},\"author\":{\"name\":\"thecodest\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\"},\"headline\":\"React Keys, Yes! You Need Them, but Why Exactly?\",\"datePublished\":\"2021-07-24T08:53:39+00:00\",\"dateModified\":\"2026-04-24T11:30:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/\"},\"wordCount\":988,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/react_keys_cover.png\",\"articleSection\":[\"Software Development\"],\"inLanguage\":\"is\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/\",\"name\":\"React Keys, Yes! You Need Them, but Why Exactly? - The Codest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/react_keys_cover.png\",\"datePublished\":\"2021-07-24T08:53:39+00:00\",\"dateModified\":\"2026-04-24T11:30:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#breadcrumb\"},\"inLanguage\":\"is\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#primaryimage\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/react_keys_cover.png\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/react_keys_cover.png\",\"width\":960,\"height\":540},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/react-keys-yes-you-need-them-but-why-exactly\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thecodest.co\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Keys, Yes! You Need Them, but Why Exactly?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"name\":\"The Codest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thecodest.co\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"is\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\",\"name\":\"The Codest\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"width\":144,\"height\":36,\"caption\":\"The Codest\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/pl.linkedin.com\\\/company\\\/codest\",\"https:\\\/\\\/clutch.co\\\/profile\\\/codest\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\",\"name\":\"thecodest\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"caption\":\"thecodest\"},\"url\":\"https:\\\/\\\/thecodest.co\\\/is\\\/author\\\/thecodest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"React Lyklar, j\u00e1! \u00de\u00fa \u00fearft \u00fe\u00e1, en af hverju n\u00e1kv\u00e6mlega? - The Codest","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thecodest.co\/is\/blogg\/react-lyklar-ja-thu-tharft-tha-en-af-hverju-nakvaemlega\/","og_locale":"is_IS","og_type":"article","og_title":"React Keys, Yes! You Need Them, but Why Exactly?","og_description":"Transforming an array into a list of elements with React is pretty straightforward, basically all you need to do is map that array and return the proper element for every array item.","og_url":"https:\/\/thecodest.co\/is\/blogg\/react-lyklar-ja-thu-tharft-tha-en-af-hverju-nakvaemlega\/","og_site_name":"The Codest","article_published_time":"2021-07-24T08:53:39+00:00","article_modified_time":"2026-04-24T11:30:22+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png","type":"image\/png"}],"author":"thecodest","twitter_card":"summary_large_image","twitter_misc":{"Written by":"thecodest","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#article","isPartOf":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/"},"author":{"name":"thecodest","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76"},"headline":"React Keys, Yes! You Need Them, but Why Exactly?","datePublished":"2021-07-24T08:53:39+00:00","dateModified":"2026-04-24T11:30:22+00:00","mainEntityOfPage":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/"},"wordCount":988,"commentCount":0,"publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"image":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png","articleSection":["Software Development"],"inLanguage":"is","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/","url":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/","name":"React Lyklar, j\u00e1! \u00de\u00fa \u00fearft \u00fe\u00e1, en af hverju n\u00e1kv\u00e6mlega? - The Codest","isPartOf":{"@id":"https:\/\/thecodest.co\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#primaryimage"},"image":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png","datePublished":"2021-07-24T08:53:39+00:00","dateModified":"2026-04-24T11:30:22+00:00","breadcrumb":{"@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#breadcrumb"},"inLanguage":"is","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/"]}]},{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#primaryimage","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/react_keys_cover.png","width":960,"height":540},{"@type":"BreadcrumbList","@id":"https:\/\/thecodest.co\/blog\/react-keys-yes-you-need-them-but-why-exactly\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thecodest.co\/"},{"@type":"ListItem","position":2,"name":"React Keys, Yes! You Need Them, but Why Exactly?"}]},{"@type":"WebSite","@id":"https:\/\/thecodest.co\/#website","url":"https:\/\/thecodest.co\/","name":"The Codest","description":"","publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thecodest.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"is"},{"@type":"Organization","@id":"https:\/\/thecodest.co\/#organization","name":"The Codest","url":"https:\/\/thecodest.co\/","logo":{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","width":144,"height":36,"caption":"The Codest"},"image":{"@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/pl.linkedin.com\/company\/codest","https:\/\/clutch.co\/profile\/codest"]},{"@type":"Person","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76","name":"thecodest","image":{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","caption":"thecodest"},"url":"https:\/\/thecodest.co\/is\/author\/thecodest\/"}]}},"_links":{"self":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/comments?post=3540"}],"version-history":[{"count":5,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3540\/revisions"}],"predecessor-version":[{"id":7970,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3540\/revisions\/7970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/media\/3541"}],"wp:attachment":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/media?parent=3540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/categories?post=3540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/tags?post=3540"}],"curies":[{"name":"vp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}