- Practice the concepts
- React exercises
- Code along
- PROJECT: Hack Your Weather I
Let's get started with some interactive exercises! Complete the exercises from the following resources:
Inside of your
React
fork, go to theweek1
folder and create a React application calledreact-exercises
(usecreate-react-app
). Inside of thesrc
folder create a JavaScript file with an appropriate name.
Exercise 1: Extreme hobbies
There's nothing better than some extreme sports to get the blood pumping.
Take a look at the following:
const hobbies = ['Surfing', 'Rock climbing', 'Mountain biking', 'Breakdancing'];
- Create 2 functional components:
<HobbyList>
and<Hobbies>
- Put the
hobbies
variable into the<HobbyList>
component. - In the
return
statement of the<HobbyList>
use themap()
function to return an instance of<Hobby>
- Pass down the hobby as a
prop
(don't forget to add thekey
prop as well!) - Test out if it works by importing it into the top level component, which in this case is
<App>
Exercise 2: Perfect customer service!
Don't you love it when a company provides great customer service?
Take a look at the following image:
In this exercise you have to create a single component that you'll reuse to display different information each time.
- Create a functional component called
<Guarantee>
- Instantiate it 3 times
- Give each component 3
props
: animg
,title
anddescription
- Pass down to each component the appropriate content. Take the images from the assets folder, inside the exercise1 folder
- Test out if it works by importing it into the top level component, which is
<App>
Exercise 3: It's higher than 10!
Let's create a simple number counter, starting from 0 until infinity!
- Create 3 functional components called
<Counter>
,<Count>
and<Button>
- Inside
<Counter>
define a state variable calledcount
(initialized with value0
) and state handler calledsetCount
- Inside
<Button>
create a<button>
with the textAdd 1!
andonClick
attribute - Pass down the
count
state variable to<Count>
, and thesetCount
to<Button>
- Inside
<Counter>
, declare a variable calledfeedback
above the return statement. Give this variable a ternary operator value: ifcount
is higher than 10 it should display the string"It's higher than 10!"
, else it displays"Keep counting..."
-
- Test out if it works by importing
<Counter>
into the top level component, which is<App>
- Test out if it works by importing
Create a new GitHub repository for this project. It's a portfolio piece!
Learning how to work with React is a fundamentally different approach to building a user interface. Therefore, we need to practice a lot!
In the following tutorial you'll learn how to a Budget Calculator
!
It might seem complicated at first, but don't worry. Aim for understanding the principle behind it to the best you can. If you ever feel in doubt: do a Google search or ask a question in Slack!
Enjoy!
Before you start, create a new folder called
project
that includes the files for the following web application you'll be building.
During this module you'll be starting a project called Hack Your Weather
! Like in the Node.js module, each week you'll add to it until it becomes a fully-fledged application you can be proud of.
Here's what you're eventually going end up with: Hack Your Weather Finished
Let's get into it.
The first step to any project is to setup your development environment. Follow the steps:
- Navigate to your
project
folder - Inside, use
create-react-app
to create a React application. Give it the namehackyourweather
- Copy and paste the file
city-weather.json
(you can find this inside of theproject-starter-files
folder) inside of your project folder: into thesrc
folder
This week you'll build the foundation of your application. It should eventually look like this:
Here are the requirements your project needs to fulfill:
- List all the cities and their weather information (taken from
city-weather.json
) - Display each city in its own box
- Each box should contain the following pieces of data:
city name
country name
weather main
weather desciption
max and min temprature
location (longitude and lattitude)
- Deploy your static site using Netlify
Hints:
- Make use of the
map()
function to show the different cities - Try to "think in components"
- Look at the JSON file and carefully look at where the useful data is found
After you've finished your list it's time to show us what you got! Upload all your files to the HackYourHomework repository (which in this case is the React repository) using GIT.
If you need a refresher, take a look at the following guide to see how it's done.
The homework that needs to be submitted is the following:
- JavaScript exercises
- Project: Hack Your Weather I
Also put the URL to your deployed website in your homework pull request!
Deadline Saturday 23.59 CET