From 78b6f8f8977e43f944fc9a26a8c8b5d77d2967ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rado=C5=A1=20Mili=C4=87ev?= <40705899+rammba@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:39:41 +0100 Subject: [PATCH 1/2] Make object data easier for translation --- src/content/learn/conditional-rendering.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/content/learn/conditional-rendering.md b/src/content/learn/conditional-rendering.md index 95be5d2e018..04d2cc32133 100644 --- a/src/content/learn/conditional-rendering.md +++ b/src/content/learn/conditional-rendering.md @@ -719,24 +719,16 @@ Another solution would be to remove the condition altogether by moving the infor ```js -const drinks = { - tea: { - part: 'leaf', - caffeine: '15–70 mg/cup', - age: '4,000+ years' - }, - coffee: { - part: 'bean', - caffeine: '80–185 mg/cup', - age: '1,000+ years' - } -}; +const drinks = [ + {name: 'tea', part: 'leaf', caffeine: '15–70 mg/cup', age: '4,000+ years'}, + {name: 'coffee', part: 'bean', caffeine: '80–185 mg/cup', age: '1,000+ years'} +]; function Drink({ name }) { - const info = drinks[name]; + const info = drinks.find(d => d.name === name); return (
-

{name}

+

{info.name}

Part of plant
{info.part}
From 785b626a20577b9fb24dbc57cced41b738f07b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rado=C5=A1=20Mili=C4=87ev?= <40705899+rammba@users.noreply.github.com> Date: Sat, 17 May 2025 08:55:33 +0200 Subject: [PATCH 2/2] Use French's solution --- src/content/learn/conditional-rendering.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/content/learn/conditional-rendering.md b/src/content/learn/conditional-rendering.md index 04d2cc32133..1df254ba326 100644 --- a/src/content/learn/conditional-rendering.md +++ b/src/content/learn/conditional-rendering.md @@ -719,13 +719,23 @@ Another solution would be to remove the condition altogether by moving the infor ```js -const drinks = [ - {name: 'tea', part: 'leaf', caffeine: '15–70 mg/cup', age: '4,000+ years'}, - {name: 'coffee', part: 'bean', caffeine: '80–185 mg/cup', age: '1,000+ years'} -]; +const drinks = { + tea: { + name: 'tea', + part: 'leaf', + caffeine: '15–70 mg/cup', + age: '4,000+ years' + }, + coffee: { + name: 'coffee', + part: 'bean', + caffeine: '80–185 mg/cup', + age: '1,000+ years' + } +}; function Drink({ name }) { - const info = drinks.find(d => d.name === name); + const info = drinks[name]; return (

{info.name}