React hooks for FaunaDB
- Install the package
npm install --save use-fauna
- Import the library
import {
useFaunaClient,
useGet,
useGetAll,
useCreate,
useDelete,
useUpdate
} from 'use-fauna'
Instantiate a Fauna client passing this hook an admin key.
const client = useFaunaClient('ADMIN_KEY')
Get all the Collections, Databases, Documents, Functions or Indexes.
const client = useFaunaClient('ADMIN_KEY')
const [getAllFunction, data, status] = useGetAll(client)
getAllFunction('collections')
getAllFunction('databases')
getAllFunction('documents', 'my-collection')
getAllFunction('functions')
getAllFunction('indexes')
Get an individual Collection, Database, Document, Function or Index.
const client = useFaunaClient('ADMIN_KEY')
const [getFunction, data, status] = useGet(client)
getFunction('collection', 'my-collection')
getFunction('database', 'my-database')
getFunction('document', 'my-collection', 'REF_ID')
getFunction('function', 'my-function')
getFunction('index', 'my-index')
Create a Collection, Database, Document or Index.
const client = useFaunaClient('ADMIN_KEY')
const [createFunction, data, status] = useCreate(client)
createFunction('collection', dataObject)
createFunction('database', dataObject)
createFunction('document', dataObject, 'my-collection')
createFunction('function', dataObject)
createFunction('index', dataObject)
Delete a Collection, Database, Document or Index.
const client = useFaunaClient('ADMIN_KEY')
const [deleteFunction, data, status] = useDelete(client)
deleteFunction('collection', 'my-collection')
deleteFunction('database', 'my-database')
deleteFunction('document', 'my-collection', 'REF_ID')
deleteFunction('function', 'my-function')
deleteFunction('index', 'my-index')
Update a Collection, Database, Document, Function, Index or Role.
const client = useFaunaClient('ADMIN_KEY')
const [updateFunction, data, status] = useUpdate(client)
updateFunction('collection', 'my-collection', dataObject)
updateFunction('database', 'my-database', dataObject)
updateFunction('document', 'my-collection', dataObject, 'REF_ID')
updateFunction('function', 'my-function', dataObject)
updateFunction('index', 'my-index', dataObject)
This hook is created using create-react-hook.