npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bbp/react-nexus

v1.3.15

Published

A set of React components for Nexus

Downloads

85

Readme

A set of React components for Nexus

Usage

Install:

npm i @bbp/react-nexus @bbp/nexus-sdk

Wrap your App with the Provider

import React from 'react';
import { render } from 'react-dom';
import { NexusProvider } from '@bbp/react-nexus';
import { createNexusClient } from '@bbp/nexus-sdk';

const nexus = createNexusClient({
  uri: 'https://sandbox.bluebrainnexus.io/v1',
});

const rootElement = document.getElementById('root');
render(
  <NexusProvider nexusClient={nexus}>
    <App />
  </NexusProvider>,
  rootElement,
);

Use the useNexus hook to call your nexus client instance:

import { useNexus } from '@bbp/react-nexus';
import { OrganizationList, ListOrgOptions } from '@bbp/nexus-sdk';

const ListOrg = ({ options }: { options?: ListOrgOptions }) => {
  const state = useNexus<OrganizationList>(nexus =>
    nexus.Organization.list(options),
  );

  if (state.loading) {
    return <p>Loading Organization...</p>;
  }
  if (state.error) {
    return <p>An error occurred: {state.error.reason}</p>;
  }
  return state.data._results.map(org => <p>{org._label}</p>);
};

<ListOrg deprecated={true} />

useNexus hook uses the default react's useEffect so you can pass a list of values to watch in order to automatically refresh a new state:

const GetOrg = ({ orgLabel }: { orgLabel: String }) => {
  const state = useNexus(nexus => nexus.Organization.get(orgLabel), [orgLabel]);
  return children({ ...state });
};

const App = () => {
  const [orgLabel, setOrgLabel] = React.useState("defaultOrg");
  return (
    <>
      <input name="org-label" onChange={e => setOrgLabel(e.target.value)} />
      <GetOrg orgLabel={orgLabel}>
        {({ data, loading, error }) => {
          if (loading) {
            return <p>Loading Organization...</p>;
          }
          if (error) {
            return <p>An error occurred loading your the organization {orgLabel}: {error.reason}</p>;
          }
          return (<p>{data._label}</p>);
        }}
      </GetOrg>
    </>
  );
}

You can also directly get the instance of the nexus client from the context:

import { useNexusContext } from '@bbp/react-nexus';

const Component = () => {
  const nexus = useNexusContext();

  // use it the way you want here
  // nexus.Organization.list().then().catch()....
}

There are some very handy components too:

import { AccessControl } from '@bbp/react-nexus';

const RenderBasedOnPermission = () => (
  <AccessControl
    permissions={["projects/read", "resources/write"]}
    path="/org"
    noAccessComponent={(missingPerms) => <NoAccess />}
    loadingComponent={<p>Loading...</p>}
  >
    <Access />
  </AccessControl>
)