generated from Code-the-Dream-School/ctd-react
-
Notifications
You must be signed in to change notification settings - Fork 32
Lesson 1.8
E Thompson edited this page Oct 19, 2021
·
3 revisions
🏗️ Work in Progress...
This lesson will teach you the following:
- Airtable
- Data Fetching
- Sign up (or login) for an Airtable account: https://airtable.com/signup
- Create a new base
- Choose a Title, Icon, and Color for your base
- Rename "Table 1" to "Default"
- Within the table, rename the first column to "Title" and delete the other columns
- Add one or more todo items to the table
- Open code editor
- Create a new file named
.env.local
in the root directory
dotenv
files use the syntaxVARIABLE=value
(See official rules)
- Navigate to https://airtable.com/account
- Click "Generate API Key"
- Copy the key from the input field
- Open
.env.local
- Create a new variable named
REACT_APP_AIRTABLE_API_KEY
- Paste the key as its value
- Click "Help" button
- Click "API Documentation" link
- Copy the "Base ID"
- Open
.env.local
- Create a new variable named
REACT_APP_AIRTABLE_BASE_ID
- Paste the ID as its value
- Open
src/App.js
- Inside the first
useEffect
hook, replace the placeholderPromise
with the following... - Using the Fetch API, create a "GET" request and pass the necessary arguments:
- url: the url of your request (in this case, "https://api.airtable.com/v0/{BASE_ID}/Default" where
{BASE_ID}
is replaced with the corresponding environment variable) - options: the object of additional request options
- url: the url of your request (in this case, "https://api.airtable.com/v0/{BASE_ID}/Default" where
- In the
fetch
options object, add the propertyheaders
as an object with the following property:- Authorization: the token to authorize the request (in this case "Bearer {API_KEY}" where
{API_KEY}
is replaced with the corresponding environment variable)
- Authorization: the token to authorize the request (in this case "Bearer {API_KEY}" where
- Chain a
then
method to your fetch call and pass it a function that returns the response JSON data - Update the
TODO_LIST_FETCH_SUCCESS
action payload to reference the new result format (hint:result.records
) - Open
src/TodoListItem.js
- Update the todo item title to reference the new object format (hint:
todo.fields.Title
)
Coming soon...
Created by Code the Dream