https://github.com/ryancharris/use-fauna
React hooks for interacting with Fauna databases
https://github.com/ryancharris/use-fauna
fauna faunadb javascript react
Last synced: 4 months ago
JSON representation
React hooks for interacting with Fauna databases
- Host: GitHub
- URL: https://github.com/ryancharris/use-fauna
- Owner: ryancharris
- Created: 2020-05-11T00:28:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T19:53:23.000Z (over 3 years ago)
- Last Synced: 2025-09-25T22:52:17.266Z (9 months ago)
- Topics: fauna, faunadb, javascript, react
- Language: TypeScript
- Homepage: https://fauna.com/
- Size: 4.21 MB
- Stars: 43
- Watchers: 2
- Forks: 3
- Open Issues: 41
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# use-fauna
> React hooks for FaunaDB
## Install
1. Install the package
```bash
npm install --save use-fauna
```
2. Import the library
```javascript
import {
useFaunaClient,
useGet,
useGetAll,
useCreate,
useDelete,
useUpdate
} from 'use-fauna'
```
## Included hooks
#### `useFaunaClient`
Instantiate a Fauna client passing this hook an admin key.
```javascript
const client = useFaunaClient('ADMIN_KEY')
```
#### `useGetAll`
Get all the Collections, Databases, Documents, Functions or Indexes.
```javascript
const client = useFaunaClient('ADMIN_KEY')
const [getAllFunction, data, status] = useGetAll(client)
getAllFunction('collections')
getAllFunction('databases')
getAllFunction('documents', 'my-collection')
getAllFunction('functions')
getAllFunction('indexes')
```
#### `useGet`
Get an individual Collection, Database, Document, Function or Index.
```javascript
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')
```
#### `useCreate`
Create a Collection, Database, Document or Index.
```javascript
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)
```
#### `useDelete`
Delete a Collection, Database, Document or Index.
```javascript
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')
```
#### `useUpdate`
Update a Collection, Database, Document, Function, Index or Role.
```javascript
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](https://github.com/hermanya/create-react-hook).