|
3 | 3 | The goal of this exercise is to learn how to think in React. |
4 | 4 |
|
5 | 5 | ## Prerequisites |
| 6 | + |
6 | 7 | You need to be comfortable writing JavaScript and HTML to do this exercise. The exercise uses the following ES6 & ES5 features: |
| 8 | + |
7 | 9 | - Module system ([import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)/ [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)) |
8 | 10 | - [Class syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) (extends, constructor) |
9 | 11 | - [Arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) |
10 | 12 | - [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) and [Array.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) |
11 | 13 |
|
12 | | -You need to have `node`and `npm`installed in your computer. |
| 14 | +You need to have `node` and `npm` installed on your computer. |
13 | 15 |
|
14 | 16 | ### If you find this exercise too difficult |
15 | 17 |
|
16 | | -If you find the exercise too difficult we recommend you to do the following basic React course from [freeCodeCamp]( |
17 | | -https://learn.freecodecamp.org/front-end-libraries/react/) before. |
| 18 | +If you find the exercise too difficult we recommend you to do the following basic React course from [freeCodeCamp](https://learn.freecodecamp.org/front-end-libraries/react/) before. |
18 | 19 |
|
19 | | -## Getting started: |
| 20 | +## Getting started |
20 | 21 |
|
21 | | -`git clone git@github.com:leanjscom/thinking-in-react.git && cd thinking-in-react && npm install && npm start` |
| 22 | +```console |
| 23 | +git clone git@github.com:reactjsacademy/thinking-in-react.git |
| 24 | +cd thinking-in-react |
| 25 | +npm install |
| 26 | +npm start |
| 27 | +``` |
22 | 28 |
|
23 | 29 | ## Exercise |
24 | 30 |
|
25 | | -Before you start, there are two types of components [Functional Components and Class Components](https://reactjs.org/docs/components-and-props.html#function-and-class-components). Try to use a Functional component if the component doesn't have state, you'll need to refactor code a few times during the next exercise :) |
26 | | - |
27 | | -### Tasks |
| 31 | +Before you start, there are two types of components [Functional Components and Class Components](https://reactjs.org/docs/components-and-props.html#function-and-class-components). |
28 | 32 |
|
29 | | -1- Refactor the “about” and “footer” sections by creating a functional component for each. Make sure everything works. |
| 33 | +```javascript |
| 34 | +function Welcome(props) { |
| 35 | + return <h1>Hello, {props.name}</h1>; |
| 36 | +} |
| 37 | +``` |
30 | 38 |
|
| 39 | +```javascript |
| 40 | +class Welcome extends React.Component { |
| 41 | + render() { |
| 42 | + return <h1>Hello, {this.props.name}</h1>; |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
31 | 46 |
|
32 | | -2- Refactor the navbar by creating a Functional Component (AKA stateless components) and pass the dependencies (this.toggleMenu in this case) via props. Make sure everything works by clicking on the "Training" button at the top right of the screen. |
| 47 | +Try to use a Functional component if the component doesn't have state, you'll need to refactor code a few times during the next exercise 😁 |
33 | 48 |
|
| 49 | +### Tasks |
34 | 50 |
|
35 | | -3- Refactor the books section by creating a functional component and pass the dependencies via props. Make sure everything works. |
36 | | - |
| 51 | +- [ ] 1. Refactor the “about” and “footer” sections by creating a functional component for each. |
| 52 | + Make sure everything works. |
37 | 53 |
|
38 | | -4- Is there any state in app that should be in the Books component? Refactor <Books> books if appropriate. Should <Books> be a Functional Component or a Class Component now? |
| 54 | +- [ ] 2. Refactor the navbar by creating a Functional Component (AKA stateless components). |
| 55 | + Pass the dependencies (`this.toggleMenu` in this case) via props. |
| 56 | + Make sure everything works by clicking on the "Training" button at the top right of the screen. |
39 | 57 |
|
| 58 | +- [ ] 3. Refactor the books section by creating a functional component and pass the dependencies via props. |
| 59 | + Make sure everything works. |
40 | 60 |
|
41 | | -5- Break <Books> down into <BookList> and <BookFilter> |
| 61 | +- [ ] 4. Is there any state in app that should be in the Books component? |
| 62 | + Refactor `<Books>` if appropriate. Should `<Books>` be a Functional Component or a Class Component now? |
42 | 63 |
|
| 64 | +- [ ] 5. Break `<Books>` down into `<BookList>` and `<BookFilter>` |
43 | 65 |
|
44 | | -6- What do you think it would make sense to componentize next? Are there any parts on that view that you can reuse? Try to explain to a mentor what you want to refactor before you code :) |
| 66 | +- [ ] 6. What do you think it would make sense to componentize next? |
| 67 | + Are there any parts on that view that you can reuse? Try to explain to a mentor what you want to refactor before you code 😁 |
45 | 68 |
|
46 | 69 | ## Articles and links |
47 | 70 |
|
48 | | -* [https://reactjs.academy/blog/introduction-to-thinking-in-react/](https://reactjs.academy/blog/introduction-to-thinking-in-react/) |
49 | | -* Basic React course from [freeCodeCamp]( |
50 | | -https://learn.freecodecamp.org/front-end-libraries/react/) |
51 | | -* [https://reactjs.org/docs/introducing-jsx.html](https://reactjs.org/docs/introducing-jsx.html) |
52 | | -* [https://reactjs.org/docs/thinking-in-react.html](https://reactjs.org/docs/thinking-in-react.html) |
53 | | -* [babel repl example](https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=MYewdgzgLgBAEgUwDZJAYRAWwA7gWWAXhgAoBKGQgPlICgYYAeAEwEsA3K-hpgCwEYqiFCACEjAPQCuPJtioB1ZKEwIYUEEwCGMXgCcEAM0IAiXlCjYIALgkSDW4FABWEAHSOtzBJgCeJqgAlBEcoACkAZTcAQWAvH19JLSpJeW5JNk5aMgBuWloWDhhgJC0ICAA5LVVTUAItVjAEPQD0zOLS8qqakz0QAHdW2QBvYVQMHDwCAF90iUyuDI4qIA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&lineWrap=false&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=6.26.0&envVersion=) |
| 71 | + |
| 72 | +- [Introduction to Thinking in React](https://reactjs.academy/blog/introduction-to-thinking-in-react/) |
| 73 | +- [A Beginner’s Guide to React](https://medium.com/leanjs/introduction-to-react-3000e9cbcd26) |
| 74 | +- [Introduction to JSX](https://reactjs.org/docs/introducing-jsx.html) |
| 75 | +- Basic React course from [freeCodeCamp](https://learn.freecodecamp.org/front-end-libraries/react/) |
54 | 76 |
|
55 | 77 | ## License |
56 | 78 |
|
|
0 commit comments