React SDK
Components
BasicProvider
To enable the features of the Basic SDK, you need to wrap your app in a <BasicProvider>
component.
BasicProvider takes 3 props:
project_id
: The project ID of your Basic projectschema
: The schema of your Basic projectdebug
: An optional prop to enable additional debug logs to the console.
Hooks
useBasic
The useBasic
hook is used to access the database and other Basic features.
Here’s a list of all the useBasic properties:
db
: The database object, which you can use to read, add, update, and delete itemsdbStatus
: Fetches the status of the databaseuser
: Fetches the user object containing the user’s ID, email, and namegetToken
: Fetches the user’s JWT tokensignin
: Function to sign a user in via the Basic OAuth flowsignout
: Function to sign a user outisSignedIn
: Boolean that checks if a user is signed inisAuthReady
: Boolean that checks if the auth is ready
Any of these properties can be accessed by destructuring the useBasic
hook.
useQuery
The useQuery
hook is used to “subscribe” to data from the database, so that it updates when the data changes.
It’s a listener for data, and enables automatic sync between the local database, users’ devices, and all other users that are connected to the same database.
We use it primarily to wrap our .get()
and .getAll()
functions, and it takes a function as an argument.
CRUD
There’s 5 functions you can use to interact with the database.
They are used in conjection with the db
property from the useBasic()
hook, and are appended in the format of db.collection('tablename').FUNCTION()
.
Fetch a single item from the table. Returns a promise, or can be used with useQuery
to “subscribe” to data changes
Fetch all items from the table. Returns a promise, or can be used with useQuery
to “subscribe” to data changes
Adds a new item to the table, returns a promise with the new item
Updates an item in the table, returns a promise with the updated item
Deletes an item from the table, returns a promise with the deleted item
Read items
There’s 2 ways to read items from the database:
.get('ID_OF_ITEM')
: Fetches a single item in a table.getAll()
: Fetches all items from the table