The goal of this exercise is to learn how to think in React.
You need to be comfortable writing JavaScript and HTML to do this exercise. The exercise uses the following ES6 & ES5 features:
- Module system (import/ export)
- Class syntax (extends, constructor)
- Arrow functions
- Array.map and Array.filter
You need to have node
and npm
installed on your computer.
If you find the exercise too difficult we recommend you to do the following basic React course from freeCodeCamp before.
git clone [email protected]:reactjsacademy/thinking-in-react.git
cd thinking-in-react
npm install
npm start
Before you start, there are two types of components Functional Components and Class Components.
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
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 😁
-
1. Refactor the “about” and “footer” sections by creating a functional component for each. Make sure everything works.
-
2. Refactor the navbar by creating a Functional Component. 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. -
3. Refactor the books section by creating a functional component and pass the dependencies via props. Make sure everything works.
-
4. Is there any state in app that should be in the Books component? Refactor
<Books>
if appropriate. Should<Books>
be a Functional Component or a Class Component now? -
5. Break
<Books>
down into<BookList>
and<BookFilter>
-
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 😁
- Introduction to Thinking in React
- A Beginner’s Guide to React
- Introduction to JSX
- Basic React course from freeCodeCamp
- https://reactjs.org/docs/lifting-state-up.html
- https://reactjs.org/docs/thinking-in-react.html
- babel repl example
This material is available for private, non-commercial use under the GPL version 3.