useBasic
TheuseBasic
hook is used to access the database and other Basic features.
Any of these properties can be accessed by destructuring the useBasic
hook.
db
The database object, which you can use to read, add, update, and delete items
dbStatus
Fetches the status of the database. Possible values are:
-
DB starts with
'LOADING'
-
Then it goes to
'CONNECTING'
-
If it connects successfully, it goes to
'ONLINE'
-
If there’s a non-fatal error, it goes to
'ERROR_WILL_RETRY'
. If there’s a fatal error, it goes to'ERROR'
-
But if it’s just offline then
'OFFLINE'
App.tsx
user
Fetches the user object containing the user’s ID, email, and name
App.tsx
getToken
Fetches the user’s JWT token, returns a promise. Since it is an async function, you can use it with
await
or .then()
.App.tsx
signin
Function to sign a user in via the Basic OAuth flow. It will redirect the user to the Basic login page, and then redirect them back to the page they were on.
App.tsx
signout
Function to sign a user out. User remains on your page after signing out, but isSignedIn will be set to false until they sign in again.
App.tsx
isAuthReady
Boolean that can be used as a loading state for your app while auth is being verified.
isAuthReady
is only triggered upon first render, and not triggered again when the user signs in or out.App.tsx
isSignedIn
Boolean that checks if a user is signed in after the
isAuthReady
boolean is true.App.tsx
useQuery
TheuseQuery
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.