Skip to content

Commit 8a40b5f

Browse files
committed
Alternative Props Syntaxes
1 parent cfd6cfc commit 8a40b5f

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

src/App.jsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { CORE_CONCEPTS } from './data/core-concepts';
12
import reactImg from './assets/react-core-concepts.png';
2-
import componentsImg from './assets/components.png';
33

44
const reactDescriptions = ['Fundamental', 'Crucial', 'Core'];
55

@@ -22,12 +22,12 @@ function Header() {
2222
);
2323
}
2424

25-
function CoreConcept(props) {
25+
function CoreConcept({ title, description, image }) {
2626
return (
2727
<li>
28-
<img src={props.img} alt={props.title} />
29-
<h3>{props.title}</h3>
30-
<p>{props.description}</p>
28+
<img src={image} alt={title} />
29+
<h3>{title}</h3>
30+
<p>{description}</p>
3131
</li>
3232
);
3333
}
@@ -41,13 +41,13 @@ function App() {
4141
<h2>Time to get started!</h2>
4242
<ul>
4343
<CoreConcept
44-
title="Components"
45-
description="The core UI building block"
46-
img={componentsImg}
44+
title={CORE_CONCEPTS[0].title}
45+
description={CORE_CONCEPTS[0].description}
46+
image={CORE_CONCEPTS[0].image}
4747
/>
48-
<CoreConcept title="Props" />
49-
<CoreConcept />
50-
<CoreConcept />
48+
<CoreConcept {...CORE_CONCEPTS[1]} />
49+
<CoreConcept {...CORE_CONCEPTS[2]} />
50+
<CoreConcept {...CORE_CONCEPTS[3]} />
5151
</ul>
5252
</section>
5353
</main>

src/data/core-concepts.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import componentsImg from '../assets/components.png';
2+
import propsImg from '../assets/config.png';
3+
import jsxImg from '../assets/jsx-ui.png';
4+
import stateImg from '../assets/state-mgmt.png';
5+
6+
export const CORE_CONCEPTS = [
7+
{
8+
image: componentsImg,
9+
title: 'Components',
10+
description:
11+
'The core UI building block - compose the user interface by combining multiple components.',
12+
},
13+
{
14+
image: jsxImg,
15+
title: 'JSX',
16+
description:
17+
'Return (potentially dynamic) HTML(ish) code to define the actual markup that will be rendered.',
18+
},
19+
{
20+
image: propsImg,
21+
title: 'Props',
22+
description:
23+
'Make components configurable (and therefore reusable) by passing input data to them.',
24+
},
25+
{
26+
image: stateImg,
27+
title: 'State',
28+
description:
29+
'React-managed data which, when changed, causes the component to re-render & the UI to update.',
30+
},
31+
];

0 commit comments

Comments
 (0)