@polybase/react
TypeScript icon, indicating that this package has built-in type declarations

0.6.6 • Public • Published

Polybase React

React wrapper for @polybase/client.

Install Polybase

npm install @polybase/react
yarn add @polybase/react

Add Polybase Provider

import * as React from 'react'
import { PolybaseProvider } from '@polybase/react'
import { Polybase } from '@polybase/client/web'

const polybase = new Polybase()

export const App = () => {
  return (
    <PolybaseProvider polybase={polybase}>
      {/* ... your app routes */}
    </PolybaseProvider>
  )
}

Read a record (with updates)

import * as React from 'react'
import { usePolybase, useRecord } from '@polybase/react'

export const Component = () => {
  const polybase = usePolybase()
  const { data, error, loading } = useRecord<OptionalCustomType>(polybase.collection('users').record('id'))

  return data.data.name
}

List collection records (with updates)

import * as React from 'react'
import { usePolybase, useCollection } from '@polybase/react'

export const Component = () => {
  const polybase = usePolybase()
  const { data, error, loading } = useCollection<OptionalCustomType>(polybase.collection('users'))

  const usersEl = map(data, ({ data }) => {
    return (
      <div key={data.id}>
        {data.name}
      </div>
    )
  })

  return usersEl
}

Readme

Keywords

none

Package Sidebar

Install

npm i @polybase/react

Weekly Downloads

22

Version

0.6.6

License

MIT

Unpacked Size

45.4 kB

Total Files

59

Last publish

Collaborators

  • patricklane
  • mateuszmlc
  • calum.moore