gongo-react

0.0.1 • Public • Published

gongo-react

React hooks for gongo-client

Copyright(c) 2020 by Gadi Cohen dragon@wastelands.net. MIT licensed.

Quickstart

import React from 'react';
import { useGongoLive } from 'gongo-react';

function App() {
  // That's it.  The component will update on any relevant change.
  const data = useGongoLive( () => db.collection('test').find() );

  return (
    <ol>
      { data.map(row => <li><code>{JSON.strinigfy(row)}</code></li> }      
    </ol>
  );
}

Hooks

useGongoLive( funcThatReturnsACursor )

LiveQuery on a result set, returns an array.

Example:

const data = useGongoLive( db => db.collection('test').find() );

useGongoOne( funcThatReturnsACursor )

LiveQuery for a single result.

Example:

const user = useGongoOne( db => db.collection('users').find({ _id: userId }) );

useGongoUserId()

LiveQuery on current userId... non-null if user is logged in.

// const opts = {
//   db: force a specific database
// };
const userId = useGongoUserId(/* opts */);

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i gongo-react

      Weekly Downloads

      0

      Version

      0.0.1

      License

      MIT

      Unpacked Size

      6.02 kB

      Total Files

      6

      Last publish

      Collaborators

      • gadicc