You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: module2/lessons/react_task_manager.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ module: 3
17
17
## Before you get started...
18
18
19
19
<sectionclass="note">
20
-
This tutorial was repurposed from another Tutorial called IdeaBox, therefore, names have been updated for Task Manager. Provided images are there as reference.
20
+
This tutorial was repurposed from another tutorial called IdeaBox, therefore, names have been updated for Task Manager. Provided images are there as reference.
21
21
</section>
22
22
23
23
You will complete this lesson on your own. Read each section carefully and completely. Moving quickly through this lesson is **not** the goal. You should move through the lesson at a pace that allows you to take solid notes and fully understand the code you are writing. We will provide lots of code blocks for you. Resist the temptation to copy and paste the code from those examples. Doing this will only hurt you in the end, as you'll be missing out on a lot, a lot, a lot of learning.
@@ -118,6 +118,8 @@ You'll also notice an `main.jsx` file. What is going on in there?
118
118
This is a great time to do some googling or ask chatGPT for help understanding.
@@ -188,6 +190,8 @@ We will use **_state_** to store data, like our list of tasks. You learned about
188
190
In order to use component state, we need to import useState hook from React. So, let's import useState hook from React, and create our App component!
189
191
190
192
```jsx
193
+
// App.jsx
194
+
191
195
import { useState } from'react';
192
196
193
197
functionApp() {
@@ -209,6 +213,8 @@ The above code is defining the App functional component in React. App returns JS
209
213
Let's keep writing our App component!
210
214
211
215
```jsx
216
+
// App.jsx
217
+
212
218
import { useState } from"react";
213
219
214
220
functionApp() {
@@ -236,6 +242,8 @@ JSX is "JavaScript and XML" - it's a handy mashup language that allows us to wri
236
242
Okay. Now try to add a paragraph tag after your `<h1>` tag. What happened?
237
243
238
244
```jsx
245
+
// App.jsx
246
+
239
247
import { useState } from"react";
240
248
241
249
functionApp() {
@@ -281,6 +289,8 @@ If you're just looking for an unflavored container for your elements (aka they a
281
289
We'll also import our App.css file. And give our <main> element a class of 'App' like so:
282
290
283
291
```jsx
292
+
// App.jsx
293
+
284
294
import { useState } from"react";
285
295
import"./App.css";
286
296
@@ -303,6 +313,8 @@ You'll notice that instead of "`class`", we're using a "`className`" attribute o
303
313
Okay. Let's come back to our App component and create _state_ - our "source of truth" for the data the app will be using.
304
314
305
315
```jsx
316
+
// App.jsx
317
+
306
318
import { useState } from"react";
307
319
import"./App.css";
308
320
@@ -333,6 +345,8 @@ For our application, we want to create a list (aka an array) of tasks.
333
345
Let's start out with a couple of default tasks, just so we can have something to look at when we begin building out the rest of our components.
334
346
335
347
```jsx
348
+
// App.jsx
349
+
336
350
import { useState } from"react";
337
351
import"./App.css";
338
352
@@ -461,6 +475,7 @@ In our App component's return statement, let's get rid of our <p> tag and pass s
461
475
462
476
```jsx
463
477
// App.jsx
478
+
464
479
// ...
465
480
return (
466
481
<main className="App">
@@ -807,6 +822,8 @@ import Form from "../Form/Form";
807
822
Then, render the Form in App's return.
808
823
809
824
```jsx
825
+
// App.jsx
826
+
810
827
return (
811
828
<main className="App">
812
829
<h1>Task Manager</h1>
@@ -1150,6 +1167,7 @@ Now, let's modify our `App.jsx` file to use these API calls instead of the hard-
1150
1167
1151
1168
```jsx
1152
1169
// App.jsx
1170
+
1153
1171
import"./App.css";
1154
1172
importTasksfrom"../Tasks/Tasks";
1155
1173
importFormfrom"../Form/Form";
@@ -1219,6 +1237,8 @@ Let's break down the changes we've made:
1219
1237
The `useEffect` hook allows us to perform side effects in our components. In this case, we're using it to fetch data from our API when the component first renders.
1220
1238
1221
1239
```jsx
1240
+
// App.jsx
1241
+
1222
1242
useEffect(() => {
1223
1243
constfetchTasks=async () => {
1224
1244
try {
@@ -1307,6 +1327,8 @@ To test your API integration:
1307
1327
2. In `app/config/initializers/cors.rb`, ensure you whitelist your React app as a trusted source:
0 commit comments