Airtable Configuration
This package is used to configure the Airtable integration for your project.
New Features!
In this version, you can now use readByID function to get a record by ID. I work on a new version to add more features. If you have any suggestions, please contact me.
Getting Started
Installation
npm install --save @theo-dev/airtable-connect
Create a .env
file in the root of your project and add the following:
REACT_APP_AIRTABLE_PERSONNAL_TOKEN=
REACT_APP_AIRTABLE_BASE_ID=
VITE_AIRTABLE_PERSONNAL_TOKEN=
VITE_AIRTABLE_BASE_ID=
Usage
-
Connection to Airtable
import { AirtableConnect } from "@theo-dev/airtable-connect";
const { AirtableData } = AirtableConnect;
const tableInstance = new AirtableData(
"Table Name",
"View Name (optional if you want to use the default view)"
);
import { AirtableConnect } from "@theo-dev/airtable-connect";
const { AirtableConfig, AirtableData } = AirtableConnect;
AirtableConfig.getBase("Personnal Token", "Base ID");
const tableInstance = new AirtableData(
"Table Name",
"View Name (optional if you want to use the default view)"
);
-
Retrieving Datas
Add function
in parameter of read function to get datas like this:
let datas = [];
tableInstance.read({
action: (dataset) => {
datas = dataset;
},
completedOnly: true,
});
-
Retrieving data by ID
Add function
in parameter of readByID function to get data like this:
let data = null;
tableInstance.readByID({
id: "RECORD_ID",
action: (dataset) => {
data = dataset;
},
});
-
Creating Data
tableInstance.create({
datas: { "Field Name": "Field Value" },
});
You can also add function
in parameter of create function to get the data like this:
let newRecord = [];
tableInstance.create({
datas: { "Field Name": "Field Value" },
action: (record) => {
newRecord = record;
},
});
-
Updating Data
tableInstance.update({
datas: { id: "ExampleID", fields: { FieldName: "Field Value" } },
});
const records = [
{
id: "ExampleID",
fields: { FieldName: "Field Value" },
},
{
id: "ExampleID",
fields: { FieldName: "Field Value" },
},
];
tableInstance.update({
datas: records,
});
You can also add function
in parameter of update function to get the data like this:
let updatedRecord = [];
tableInstance.update({
datas: { id: "ExampleID", fields: { FieldName: "Field Value" } },
action: (record) => {
updatedRecord = record;
},
});
-
Deleting Data
Add function
in parameter of delete function to get the deleted data like this:
let deletedRecord = [];
tableInstance.delete({
id: "ExampleID",
action: (record) => {
deletedRecord = record;
},
});
Package Dependencies
Credits