Catalog npm
PACKAGE EXPLORERView in registry

3box-react-hooks

npm

React hooks wrapping the 3box API

3boxboxhooksprofilereactspace
Versions collected9
Direct dependencies23From release 2.0.1
Last observed20 Oct, 19:31 UTC

README

Current package documentation

3box-react-hooks

React hooks wrapping 3box API

Changelog

2.0.0 has a new API that is more in line with the 3box API. The new version also enables more lightweight builds with 3box-react-hooks/dist/api.

Installation

npm i -S 3box-react-hooks

Api

FunctionArgumentsReturnCorresponds to
useProfileaddress[, opts]profileBox.getProfile
usePublicSpaceaddress, space name[, opts]spaceBox.getSpace
useBoxaddress, provider[, opts]boxBox.openBox
useSpacespace name, box[, opts]spacebox.openSpace
useDelayedBoxaddress, provider[, opts][box, open]-
useDelayedSpacespace name, box[, opts][space, open]-

Delayed box and space

Delayed hooks can be used to postpone authentication. For example if a box should be opened when the user presses an authentication button. The return value from the hooks contains box/space which is null until authenticated and open which is a function that opens the box/space.

If the box and spaces are supposed to be opened at the same time, only the box needs to be delayed since the space waits for box to not be null before opening. There's an example below.

Optimize build for read-only operations

useProfile and usePublicSpace can be used by importing 3box-react-hooks/dist/api for a more lightweight build.

Example

import { useProfile, useBox, useSpace } from '3box-react-hooks';

const MyComponent = (props) => {
  const address = '0x88E146E0fd0F5AaCbc4f94365dF9f599A90139F1';
  const profile = useProfile(address);
  const box = useBox(address, window.ethereum);
  const space = useSpace('exampleSpace', box);

  const email = await box.private.get('email');
  const spaceValue = await space.private.get('key');

  return (
    <>
      <div>{profile.emoji}</div>
      <div>{email}</div>
      <div>{spaceValue}</div>
    </>
  );
}

Delayed box and space

import { useDelayedBox, useSpace } from '3box-react-hooks';

const MyComponent = (props) => {
  const address = '0x88E146E0fd0F5AaCbc4f94365dF9f599A90139F1';
  const [box, open] = useDelayedBox(address, window.ethereum);
  const space = useSpace('exampleSpace', box);

  const email = await box.private.get('email');
  const spaceValue = await space.private.get('key');

  return (
    <>
      <div>{email}</div>
      <div>{spaceValue}</div>
      <button onClick={open}>Authenticate</button>
    </>
  );
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 9

Collected releases
VersionPublishedDirect dependenciesOpen version
2.0.1Registry latest30 May 201923
2.0.030 May 201923
1.1.425 Apr 201920
1.1.321 Apr 201920
1.1.218 Apr 201920
1.1.117 Apr 201920
1.1.016 Apr 201911
1.0.114 Apr 201911
1.0.014 Apr 201911

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
raksooo/3box-react-hooks

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:31 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:54b6ffb1e07d8992fd9e545c66096fb343eb3a3362ce534b33e32dce279b294c