Skip to content

Commit ed150ef

Browse files
author
Noer Paanakker
committed
added w3/4 project instructions, finished readings w3/4
1 parent c38e96b commit ed150ef

File tree

11 files changed

+227
-43
lines changed

11 files changed

+227
-43
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

assets/project/week3.png

107 KB
Loading

assets/project/week4.png

70.7 KB
Loading

hand-in-homework-guide.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# How to hand in homework
2+
3+
In this module you'll submit your homework only using GIT and GitHub.
4+
5+
1. [GitHub](https://www.github.com/HackYourFuture/React)
6+
7+
## 1. GitHub homework guide
8+
9+
Follow the walkthrough to learn how to submit your homework for each week:
10+
11+
ONE TIME ONLY (START OF EVERY MODULE)
12+
13+
1. Create a [fork](https://help.github.com/en/articles/fork-a-repo) of the teacher's forked repository (ask in Slack what the URL for it is). You do this by using the `fork` option on the top right
14+
2. Navigate to the URL of the cloned repository (it should be in your personal GitHub account, under "repositories")
15+
3. Clone the repository, using SSH, to your local machine. You can do this by typing in `git clone <git url>` in the command line
16+
4. On your local machine, navigate to the folder using the command line
17+
5. Make sure you've cloned it correctly by running `git status` from the command line.
18+
19+
EVERY WEEK
20+
21+
1. Create a new branch for each week you have homework. For example, for the week 1 homework for React create a branch called `week-1-homework-YOUR_NAME`
22+
2. Inside the correct week folder, create another folder called `homework`. Make your homework files in there, while on the correct branch
23+
3. Once you're finished, add and commit everything. Make the commit message meaningful, for example `finished project for homework week1`
24+
4. Push the branch to your forked repository
25+
5. On the GitHub page of your forked repository, click on the `create pull request` button. Make sure the `base repository` is your teacher's repository, on branch master
26+
6. Give the pull request a title in the following format:
27+
28+
```markdown
29+
Homework week 1 <Your name>
30+
```
31+
32+
7. Submit the pull request from your forked repository branch into the `master` branch
33+
8. Do a little victory dance because you did it! Good job!
34+
35+
For a visual walkthrough the steps please watch the following video one of our teachers, Unmesh Joshi, has made:
36+
37+
- [GitHub Homework flow](https://www.youtube.com/watch?v=2qJPAVTiKPE)
38+
39+
If you have any questions or if something is not entirely clear ¯\\\_(ツ)\_/¯, please ask/comment on Slack!

week1/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ In our example, it means that our `props` can only move from `<Contact>` > `<Add
196196

197197
A static website is a collection of HTML, CSS and client-side JavaScript files. That's it. It is usually only a frontend, hosted on a web server that only serves the pages the client asks for (for example, `/`, `/about` or `/privacy`).
198198

199-
As you've learned in the Node.js module, we can use server-side frameworks like `Express` or just native Node.js modules (like `http`)
199+
As you've learned in the Node.js module, we can use server-side frameworks like `Express` or just native Node.js modules (like `http`) in order to serve our static files to a client.
200+
201+
But what if we don't want to setup a whole web server to do this?
202+
203+
### Static site generators
200204

201205
We call these `static site generators`. They take a lot of the basic web server setup out of our hands. All we have to do is upload our frontend (in other words, our static website) to that particular service's web server and that's it. The generator creates a URL for us that we can use to access our website.
202206

@@ -211,6 +215,6 @@ To learn more about static site generators, study the following:
211215
- [The Reign of Static Site Generators](https://www.netlify.com/blog/2018/07/12/the-reign-of-static-site-generators/)
212216
- [Why use a Static Site Generator](https://www.youtube.com/watch?v=mDKQGANttyE)
213217

214-
### Static site generators
218+
## Finished?
215219

216-
[React Philosophy](https://reallifeprogramming.com/react-philosophy-e8cdea991599), [Components](https://medium.com/the-andela-way/understanding-react-components-37f841c1f3bb), [JSX](https://reactgo.com/learn-react-jsx-detailed/), [Props](https://www.robinwieruch.de/react-pass-props-to-component/)
220+
Are you finished with going through the materials? High five! If you feel ready to get practical, click [here](./MAKEME.md).

week2/MAKEME.md

+25-10
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ We'll start the week off with some online exercises again. Complete the exercise
1515

1616
## **2. React exercises**
1717

18-
> Inside of your `React` fork, go to the `week1` folder and create a React application called `react-exercises` (use `create-react-app`). Inside of the `src` folder create a JavaScript file with an appropriate name.
18+
> Inside of your `React` fork, go to the `week2` folder and create a React application called `react-exercises` (use `create-react-app`). Inside of the `src` folder create a JavaScript file with an appropriate name.
1919
2020
**Exercise 1: New friend on demand**
2121

2222
What if there was an app that could generate a new friend, instantly? How about we make one!
2323

2424
In this exercise we'll be using the following API endpoint: `https://www.randomuser.me/api?results=1`
2525

26-
1. Create 2 functional components called `<Friend>` and `<Button>`
27-
2. Inside create a state variable called `friend` (with initial state of `{}`) and state handler `setFriend`
28-
3. Inside (before the return statement) also create a function called `getFriend`. The purpose of this function is to make an API call to `https://www.randomuser.me/api?results=1`. You can either use `fetch` or `axios`. At the end of the function reassign the `friend` state value using `setFriend`
26+
1. Create 3 functional components called `<Friend>`, `<FriendProfile>` and `<Button>`
27+
2. Inside `<Friend>` create a state variable called `friend` (with an initial state of `{}`) and state handler `setFriend`
28+
3. Inside `<Friend>` (before the return statement) also create a function called `getFriend`. The purpose of this function is to make an API call to `https://www.randomuser.me/api?results=1`. You can either use `fetch` or `axios`. At the end of the function reassign the `friend` state variable using `setFriend`
2929
4. Inside the `<Button>` component, create a `<button>` that has the text "Get a friend!" and `onClick` attribute
3030
5. Pass down the function `getFriend` to `<Button>`
31-
6. NOT FINISHED
32-
7. Test if everything works by importing it into the top level component, which is `<App>`
31+
6. Inside `<FriendProfile>` create an `<ul>` that showcases the following attributes of the person: The first and last names, the address and country, the email address, and finally also the phone number
32+
7. Pass down the `friend` state variable to the `<FriendProfile>`
33+
8. Test if everything works by importing it into the top level component, which is `<App>`
3334

3435
**Exercise 2: Dog photo gallery**
3536

@@ -39,13 +40,25 @@ In this exercise we'll be using the following API endpoint: `https://dog.ceo/api
3940

4041
1. Create 3 functional components: `<DogGallery>`, `<DogPhoto>` and `<Button>`
4142
2. Inside `<DogGallery>` create a state variable called `dogPhotos` (initialize with value `[]`) and state handler `setDogPhotos`
42-
3. Inside (before the return statement) also create a function called `getDogPhoto`. The purpose of this function is to make an API call to `https://dog.ceo/api/breeds/image/random`. You can either use `fetch` or `axios`. At the end of the function push the new `dog image URL` into the `dogPhotos` array state value using `setDogPhotos`
43+
3. Inside (before the return statement) also create a function called `getDogPhoto`. The purpose of this function is to make an API call to `https://dog.ceo/api/breeds/image/random`. You can either use `fetch` or `axios`. At the end of the function push the new `dog image URL` into the `dogPhotos` array state variable using `setDogPhotos`
4344
4. Inside the `<Button>` component, create a `<button>` that has the text "Get a dog!" and `onClick` attribute
4445
5. Pass down the function `getDogPhoto` to `<Button>`
45-
6. Inside `<DogGallery>` return all the dogs stored in the `dogPhotos` array using the `map()` function. However, when there are no dogs yet make sure to display the message "Get your first dog by clicking the button!"
46-
7. Test your components by importing it into the top level
46+
6. Inside `<DogGallery>` return all the dogs stored in the `dogPhotos` array using the `map()` function. Pass down each `dogPhoto` into an instance of `<DogPhoto>`.
47+
7. However, when there are no dogs in the array yet make sure to display the message "Get your first dog by clicking the button!"
48+
8. Test your components by importing it into the top level component, which is `<App>`
4749

48-
**Exercise 3**
50+
**Exercise 3: Random Joke Generator**
51+
52+
Never run out of jokes with the Random Joke Generator!
53+
54+
In this exercise we'll be using the following API endpoint: `https://official-joke-api.appspot.com/random_joke`
55+
56+
1. Create 2 functional components: `<RandomJoke>` and `<Joke>`
57+
2. Inside `<RandomJoke>` create a state variable called `joke` (with initial state `{}`) and state handler `setJoke`
58+
3. Make use of the `useEffect` hook to make an asynchronous API call to the API endpoint. Put the end result into the state variable using `setJoke`
59+
4. Now pass the reassigned state variable `joke` to the `<Joke>` component
60+
5. Inside the `<Joke>` component, display the `setup` and `punchline` attributes in 2 `<p>` tags
61+
6. Test out your work by importing your components into the top level component, which is `<App>`
4962

5063
## **3. Code along**
5164

@@ -77,6 +90,8 @@ Here are the requirements your project needs to fulfill:
7790
- Make an API call when the button is clicked
7891
- Display the city + weather information similar to week 1
7992
- Make a component for the search
93+
- Incorporate error handling for the API call
94+
- Show user feedback when there are no cities searched for yet
8095

8196
Hints:
8297

week2/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Like any other system, React is always evolving. Before we had Hooks, we used to
2323
```js
2424
class Example extends React.Component {
2525
state = {
26-
exampleMessage: 'This message is for the example'
26+
exampleMessage: "This message is for the example"
2727
};
2828

2929
render() {
@@ -108,4 +108,17 @@ Forms have always been slightly different than any other element in HTML. So it
108108

109109
### Controlled vs. uncontrolled
110110

111+
These terms refer to whether or not a component has its own state or not. We're talking about a `controlled` component when it doesn't have its own state: it's being controlled by
112+
113+
A component is `uncontrolled` when it does have state, meaning state values are defined within in.
114+
115+
Learn more about this here:
116+
117+
- [Controlled and uncontrolled elements](https://www.youtube.com/watch?v=nSGZEQa5C_c)
118+
- [How React Hooks change the way we build forms](https://www.youtube.com/watch?v=8yo44xN7-nQ)
119+
111120
### EventListeners & preventing default behavior
121+
122+
## Finished?
123+
124+
Are you finished with going through the materials? High five! If you feel ready to get practical, click [here](./MAKEME.md).

week3/MAKEME.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ This week we'll practice some (hopefully) familiar concepts, with some online ex
1515

1616
## **2. React exercises**
1717

18-
> Inside of your `React` fork, go to the `week3` folder and create a folder called `react-exercises`. For each exercise create a new folder (call it `exercise` follwed by the right number) and create 3 files: and `index.html`, `script.js` and `style.css`.
19-
20-
**Exercise 1**
21-
22-
**Exercise 2**
23-
24-
**Exercise 3**
18+
**No exercises this week**
2519

2620
## **3. Code along**
2721

@@ -31,9 +25,26 @@ In the following tutorial you'll learn how to make
3125

3226
## **4. PROJECT: Hack Your Weather III**
3327

34-
> Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to.
28+
> Make sure you're building on last week's codebase.
29+
30+
The main additions you'll add this week is to (1) keep adding to the list of already searched cities and (2) allow users to remove a city from previous search result.
31+
32+
### 1. Requirements
33+
34+
By the end of this week's assignment your application should look similar to this:
35+
36+
![Week 3 Wireframe](../assets/project/week3.png)
37+
38+
Here are the requirements your project needs to fulfill:
39+
40+
- Any time a user searches for a new city, add it to a list of already searched cities
41+
- Allow a user to delete a search entry, by clicking the "X"
42+
- Only allow a user to use the "Search City" button when the input field has at least 1 character
43+
44+
Hints:
3545

36-
> Before you start, create a new folder called `project` that includes the files for the following app you'll be building.
46+
- Think about what data structure makes most sense to use
47+
- Make use of `filter()` when removing cities
3748

3849
## **SUBMIT YOUR HOMEWORK!**
3950

@@ -43,7 +54,6 @@ If you need a refresher, take a look at the following [guide](../hand-in-homewor
4354

4455
The homework that needs to be submitted is the following:
4556

46-
1. React exercises
47-
2. Project: Hack Your Weather III
57+
1. Project: Hack Your Weather III
4858

4959
_Deadline Saturday 23.59 CET_

week3/README.md

+68-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,78 @@ These are the topics for week 3:
66

77
1. Hooks II
88
- Building custom hooks
9-
2. Third party components
9+
- Using other people's custom hooks
10+
2. Third party React tools
11+
- UI toolkits
12+
- Utilities
1013

1114
## 1. Hooks II
1215

1316
### Building custom hooks
1417

15-
## 2. Third party components
18+
One of the main benefits of using the React hooks (like `useState`, `useEffect`, etc.), is that they can be used in any functional component.
1619

17-
Why write everything yourself when you can access other's software, for free? Like with any software ecosystem, whether it's React, Angular or Vue, there will be developers who've made certain functionalities easier for you to
20+
However, that's not the only big benefit. Another one is that it allows us to isolate `stateful logic` into a reusable function that can be used in other functional components.
1821

19-
It's highly recommended
22+
This `stateful logic` is just a complicated way for saying state variables and the instructions that manipulate it.
23+
24+
In a custom hook we can create state everytime we use it, and modify it according to the instructions that are included in the hook. This is the strength of using custom hooks: by defining custom hooks we can replicate a certain functionality for us to use in multiple different functional components.
25+
26+
In terms of implementation, a custom Hook is simply a JavaScript function whose name starts with ”use” (for example, `useSomeAction`). It incorporates existing hooks (like `useState`) and adds logic to it.
27+
28+
Study the following to learn more about it:
29+
30+
- [Building your own hooks](https://reactjs.org/docs/hooks-custom.html)
31+
- [Building Custom React Hooks](https://medium.com/prototyped/building-custom-react-hooks-f6aad8567825)
32+
33+
### Using other people's custom hooks
34+
35+
Like anything in development, once someone has found a solution to a common problem it (hopefully) gets published for everyone to use. This is also the case with `hooks`.
36+
37+
Check the following resources out to learn more about these custom hooks others have made for you to use:
38+
39+
- [usehooks.com](https://usehooks.com/)
40+
41+
## 2. Third party React tools
42+
43+
Third party React tools can roughly be divided into 2 categories:
44+
45+
1. UI toolkits
46+
2. Utilities
47+
48+
### UI toolkits
49+
50+
These kind of component libraries serve to **structure your user interface**. If you've ever worked with a CSS framework, this is what it means.
51+
52+
Popular presentational component libraries are the following:
53+
54+
- [Semantic UI](https://react.semantic-ui.com/)
55+
- [Material UI](https://material-ui.com/)
56+
- [Shards](https://designrevision.com/docs/shards-react/getting-started)
57+
58+
All of these are called `UI toolkits` and provide components that structure a particular part of your page.
59+
60+
For example, Let's say you want to add a `button` component in your form. You could make it yourself. Or you could take it from the toolkit!
61+
62+
```js
63+
import React from "react";
64+
import { Button } from "semantic-ui-react";
65+
66+
const ButtonExampleButton = () => <Button>Click Here</Button>;
67+
68+
export default ButtonExampleButton;
69+
```
70+
71+
### Utilities
72+
73+
There are also tools that solve certain problems within the React ecosystem.
74+
75+
- [Enzyme](https://github.com/airbnb/enzyme) is a React-specific component testing tool, that makes it easier to test your React Components' output
76+
- [Redux](https://redux.js.org/introduction/getting-started) is a state management tool, used to make it possible to connect every component directly to the entire state and thus eliminates the need to use props or callbacks.
77+
- [React Intl](https://github.com/formatjs/react-intl) is a tool that provides an application the ability to have multiple languages (English, Dutch, etc.) within the application
78+
79+
All of these tools are not necessarily React-specific, but allow us to use React in order to create more engaging, feature-rich applications.
80+
81+
## Finished?
82+
83+
Are you finished with going through the materials? High five! If you feel ready to get practical, click [here](./MAKEME.md).

week4/MAKEME.md

+34-11
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ Let's finish the online exercises. Start from `Review Using Props with Stateless
1515

1616
## **2. React exercises**
1717

18-
> Inside of your `React` fork, go to the `week4` folder and create a folder called `react-exercises`. For each exercise create a new folder (call it `exercise` follwed by the right number) and create 3 files: and `index.html`, `script.js` and `style.css`.
19-
20-
**Exercise 1**
21-
22-
**Exercise 2**
23-
24-
**Exercise 3**
18+
**No exercises this week**
2519

2620
## **3. Code along**
2721

@@ -31,9 +25,39 @@ In the following tutorial you'll learn how to
3125

3226
## **4. PROJECT: Hack Your Weather IV**
3327

34-
> Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to.
28+
> Make sure you're building on last week's codebase.
29+
30+
This week we'll finish our application by integrating 2 things: `client-side routing` with [React-Router-Dom](https://reacttraining.com/react-router/web/guides/quick-start) and `charting` our data (in either hourly or five day forecasts).
31+
32+
### 1. Setup
33+
34+
1. Install the following packages: [React Router Dom](https://www.npmjs.com/package/react-router-dom) and [Recharts](https://www.npmjs.com/package/recharts)
35+
36+
```
37+
npm install react-router-dom recharts
38+
```
39+
40+
### 2. Requirements
41+
42+
At the end of the week the user interface of your application will look mostly the same, but with an additional page:
43+
44+
![Week 4 Wireframe](../assets/project/week4.png)
45+
46+
Here are the requirements your project needs to fulfill:
47+
48+
- Divide your page into 2 different routes (`/` and `/:cityId`), using `react-router-dom`
49+
- Allow users to click on the searched city to open the city page
50+
- The city page will be on a different route identified by the city id (make use of the `<Link>` component given by `react-router-dom`)
51+
- On the city page there will be several things:
52+
- Two tabs, one for the hourly forecast and the other for a 5 day forecast
53+
- A chart (made with `recharts`) that displays the correct data according to which tab is active
54+
- Clicking on a tab will do 2 things: (1) make an API call to get the right data (using the city id from the URL params), and (2) switch the active component (from the hourly forecast to the five day forecast and vice versa)
55+
- Add a "Back" button to go back to `/`, on the city page
56+
57+
Hints:
3558

36-
> Before you start, create a new folder called `project` that includes the files for the following app you'll be building.
59+
- Read the documentation to get a basic sense of what problems both `react-router-dom` and `recharts` are trying to solve, and to learn how to use them
60+
- Make sure to have a clear overview of your application so far, before you add this week's features to it
3761

3862
## **SUBMIT YOUR HOMEWORK!**
3963

@@ -43,7 +67,6 @@ If you need a refresher, take a look at the following [guide](../hand-in-homewor
4367

4468
The homework that needs to be submitted is the following:
4569

46-
1. React exercises
47-
2. Project: Hack Your Weather IV
70+
1. Project: Hack Your Weather IV
4871

4972
_Deadline Saturday 23.59 CET_

0 commit comments

Comments
 (0)