Skip to content

Make some of the Flamelink SDK's functionality available as React Hooks

Notifications You must be signed in to change notification settings

jperasmus/flamelink-react-hooks

Repository files navigation

flamelink-react-hooks

Some Flamelink SDK functionality exposed as React Hooks

Installation

npm install -S flamelink-react-hooks

Usage

flamelink-react-hooks uses the Flamelink SDK internally, so please take a look at the Installation & Usage sections for the SDK to see how you can instantiate the flamelinkApp instance.

import { createFlamelinkHooks } from 'flamelink-react-hooks'
import flamelink from 'flamelink/app'
import 'flamelink/content'
import 'flamelink/storage'

const flamelinkApp = flamelink(/* init flamelink app */)

const { useContent, useContentOnce } = createFlamelinkHooks({ flamelinkApp })

const YourComponent = function(props) {
  const [error, content] = useContent({ schemaKey: 'homepage' })

  if (error) {
    return <p>Error Error Error</p>
  }

  return (
    <section>
      <h1>{content.title}</h1>
      <p>{content.body}</p>
    </section>
  )
}

Available Hooks

The following hooks are currently available

useContent

This hook sets up a real-time subscription for the content you want.

returns: [error, content] Array with the first item an error object, otherwise it will be null and the second item will be the content payload - initially it will be null

useContentOnce

This hook queries once for the content you want without setting up a real-time connection.

returns: [error, content] Same as useContent

useNav

This hook sets up a real-time subscription for the navigation you want.

returns: [error, navigation] Array with the first item an error object, otherwise it will be null and the second item will be the navigation payload - initially it will be null

useNavOnce

This hook queries once for the navigation you want without setting up a real-time connection.

returns: [error, navigation] Same as useNav

useUsers

This hook sets up a real-time subscription for the users you want.

returns: [error, users] Array with the first item an error object, otherwise it will be null and the second item will be the users payload - initially it will be null

useUsersOnce

This hook queries once for the users you want without setting up a real-time connection.

returns: [error, users] Same as useUsers

History

Discover the release history by heading on over to the releases page.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Contributors

These amazing people have contributed code to this project:

License

Unless stated otherwise all works are:

and licensed under:

About

Make some of the Flamelink SDK's functionality available as React Hooks

Resources

Stars

Watchers

Forks

Packages