This assignment will teach you the following:
- React DOM
- Component Definition
- Component Instantiation
- React Components
Merge your pull request from the previous lesson (if you haven't already):
Checkout your main branch and pull changes:
git checkout main
git pull
Create a new local branch to work on separate from the main
branch:
git checkout -b lesson-1-2
Now, open the project directory in your code editor and continue to the next section.
- Inside
/src
directory, create a new file calledTodoList.js
- Open
/src/TodoList.js
- Create a new functional React component (see below)
- Import
React
from "react" npm package - Declare a function named
TodoList
- Export
TodoList
function as default module
- Import
- Add a multi-line return statement to your
TodoList
function (this is where we will insert JSX)- hint: use parenthesis for multi-line return
- Move list JSX from
App.js
toTodoList.js
(see below)- Open
/src/App.js
- Cut (copy and remove) the entire list element (
<ul>
) code - Open
/src/TodoList.js
- Inside the multi-line return, paste the list element (
<ul>
) code
- Open
- Move
todoList
array fromApp.js
toTodoList.js
(see below)- Open
/src/App.js
- Cut (copy and remove) the entire
todoList
variable declaration - Open
/src/TodoList.js
- Below the import, paste the
todoList
variable
- Open
- Refactor
App.js
to use newTodoList
component (see below)- Open
/src/App.js
- Below
React
, importTodoList
- Below the level-one heading, use the
TodoList
component
- Open
- Run your application and view in browser
- Verify that your Todo List still appears correctly
- Inside
/src
directory, create a new file calledAddTodoForm.js
- Open
/src/AddTodoForm.js
- Create a new functional React component (see below)
- Import
React
from "react" npm package - Declare a function named
AddTodoForm
- Export
AddTodoForm
function as default module
- Import
- Add a multi-line return statement to your
AddTodoForm
function (this is where we will insert JSX)- hint: use parenthesis for multi-line return
- Write JSX for "Add Todo" form (see below)
- Create a
<form>
element - Inside the
<form>
element, create a<label>
element with text "Title" - Next, create a text
<input>
element withid
"todoTitle" - Add
htmlFor
attribute to<label>
element with same value asid
above - Next, create a submit
<button>
element with text "Add"
- Create a
- Use
AddTodoForm
component inApp.js
(see below)- Open
/src/App.js
- Below
React
, importAddTodoForm
- Below the level-one heading, use the
AddTodoForm
component
- Open
- Run your application and view in browser
- Verify that "Add Todo" form appears below heading
Check the status of your local repository to double-check the changes you made:
git status
Stage the file(s) that you edited:
git add .
Check the status again and notice that the changes from before are now staged:
git status
Create a commit for the changes you made and add a message describing the changes you made:
Note: Replace
<message>
with your message
git commit -m "<message>"
Push your commit to the remote repository (visible in GitHub):
git push
Check the log to make sure your commit has been published:
git log --oneline
Create a pull request and submit:
Created by Code the Dream