|
|
|
@ -976,6 +976,25 @@ const UserCard = ({ user: { firstName, lastName, image } }) => (
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A button component
|
|
|
|
|
|
|
|
|
|
const Button = ({ text, onClick, style }) => (
|
|
|
|
|
<button style={style} onClick={onClick}>
|
|
|
|
|
{text}
|
|
|
|
|
</button>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const buttonStyles = {
|
|
|
|
|
backgroundColor: '#61dbfb',
|
|
|
|
|
padding: 10,
|
|
|
|
|
border: 'none',
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
margin: 3,
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
color: 'white',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Main Component
|
|
|
|
|
const Main = ({ user, techs, greetPeople, handleTime }) => (
|
|
|
|
|
<main>
|
|
|
|
@ -985,8 +1004,8 @@ const Main = ({ user, techs, greetPeople, handleTime }) => (
|
|
|
|
|
<TechList techs={techs} />
|
|
|
|
|
</ul>
|
|
|
|
|
<UserCard user={user} />
|
|
|
|
|
<Button text='Greet People' onClick={greetPeople} />
|
|
|
|
|
<Button text='Show Time' onClick={handleTime} />
|
|
|
|
|
<Button text='Greet People' onClick={greetPeople} style={buttonStyles} />
|
|
|
|
|
<Button text='Show Time' onClick={handleTime} style={buttonStyles} />
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
)
|
|
|
|
@ -1011,7 +1030,7 @@ const App = () => {
|
|
|
|
|
firstName: 'Asabeneh',
|
|
|
|
|
lastName: 'Yetayeh',
|
|
|
|
|
},
|
|
|
|
|
date: new Date(),
|
|
|
|
|
date: new Date(), // date needs to be formatted to a human readable format
|
|
|
|
|
}
|
|
|
|
|
const date = new Date()
|
|
|
|
|
const techs = ['HTML', 'CSS', 'JavaScript']
|
|
|
|
@ -1043,94 +1062,6 @@ const rootElement = document.getElementById('root')
|
|
|
|
|
ReactDOM.render(<App />, rootElement)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
import React from 'react'
|
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
|
|
|
|
|
|
const welcome = 'Welcome to 30 Days Of React'
|
|
|
|
|
const title = 'Getting Started React'
|
|
|
|
|
const subtitle = 'JavaScript Library'
|
|
|
|
|
const author = {
|
|
|
|
|
firstName: 'Asabeneh',
|
|
|
|
|
lastName: 'Yetayeh',
|
|
|
|
|
}
|
|
|
|
|
const date = 'Oct 4, 2020'
|
|
|
|
|
|
|
|
|
|
const copyRight = 'Copyright 2020'
|
|
|
|
|
const techs = ['HTML', 'CSS', 'JavaScript']
|
|
|
|
|
|
|
|
|
|
// Header Component
|
|
|
|
|
const Header = (props) => (
|
|
|
|
|
<header>
|
|
|
|
|
<div className='header-wrapper'>
|
|
|
|
|
<h1>{props.title}</h1>
|
|
|
|
|
<h2>{props.subtitle}</h2>
|
|
|
|
|
<h3>
|
|
|
|
|
{props.author.firstName} {props.author.lastName}
|
|
|
|
|
</h3>
|
|
|
|
|
<p>{props.date}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// User Card Component
|
|
|
|
|
const UserCard = ({ firstName, lastName, image }) => (
|
|
|
|
|
<div className='user-card'>
|
|
|
|
|
<img src={image} alt={firstName} />
|
|
|
|
|
<h2>
|
|
|
|
|
{firstName}
|
|
|
|
|
{lastName}
|
|
|
|
|
</h2>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TechList Component
|
|
|
|
|
const TechList = (props) => {
|
|
|
|
|
const techsFormatted = props.techs.map((tech) => <li key={tech}>{tech}</li>)
|
|
|
|
|
return techsFormatted
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Main Component
|
|
|
|
|
const Main = () => (
|
|
|
|
|
<main>
|
|
|
|
|
<div className='main-wrapper'>
|
|
|
|
|
<p>Prerequisite to get started react.js:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<TechList techs={techs} />
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Footer Component
|
|
|
|
|
const Footer = (props) => (
|
|
|
|
|
<footer>
|
|
|
|
|
<div className='footer-wrapper'>
|
|
|
|
|
<p>{props.copyRight}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</footer>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// The App, or the parent or the container component
|
|
|
|
|
const App = () => (
|
|
|
|
|
<div className='app'>
|
|
|
|
|
<Header
|
|
|
|
|
welcome={welcome}
|
|
|
|
|
title={title}
|
|
|
|
|
subtitle={subtitle}
|
|
|
|
|
author={author}
|
|
|
|
|
date={date}
|
|
|
|
|
/>
|
|
|
|
|
<Main />
|
|
|
|
|
<Footer copyRight={copyRight} />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const rootElement = document.getElementById('root')
|
|
|
|
|
// we render the JSX element using the ReactDOM package
|
|
|
|
|
ReactDOM.render(<App />, rootElement)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## propTypes
|
|
|
|
|
|
|
|
|
|
The propTypes package help as to assign the data types of the props we passed to a component.
|
|
|
|
|