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

@bucketco/react-sdk

v2.0.1

Published

React client side library for [Bucket.co](https://bucket.co)

Downloads

526

Readme

Bucket React SDK

React client side library for Bucket.co

Install

Install via npm:

npm i @bucketco/react-sdk

Setup

1. Define Features (optional)

To get type safe feature definitions, extend the definition of the Features interface and define which features you have. See the example below for the details.

If no explicit feature definitions are provided, there will be no types checked feature lookups.

Example:

import "@bucketco/react-sdk";

// Define your features by extending the `Features` interface in @bucketco/react-sdk
declare module "@bucketco/react-sdk" {
  interface Features {
    huddle: boolean;
    recordVideo: boolean;
  }
}

2. Add the BucketProvider context provider

Add the BucketProvider context provider to your application. This will initialize the Bucket SDK, fetch features and start listening for automated feedback survey events.

Example:

import { BucketProvider } from "@bucketco/react-sdk";

<BucketProvider
  publishableKey="{YOUR_PUBLISHABLE_KEY}"
  company={{ id: "acme_inc" }}
  user={{ id: "john doe" }}
  loadingComponent={<Loading />}
  fallbackFeatures={["huddle"]}
>
  {/* children here are shown when loading finishes or immediately if no `loadingComponent` is given */}
</BucketProvider>;
  • publishableKey is used to connect the provider to an environment on Bucket. Find your publishableKey under Activity on https://app.bucket.co.

  • company, user and otherContext make up the context that is used to determine if a feature is enabled or not. company and user contexts are automatically transmitted to Bucket servers so the Bucket app can show you which companies have access to which features etc.

    If you specify company and/or user they must have at least the id property plus anything additional you want to be able to evaluate feature targeting against. See "Managing Bucket context" below.

  • fallbackFeatures is a list of strings which specify which features to consider enabled if the SDK is unable to fetch features.

  • loadingComponent lets you specify an React component to be rendered instead of the children while the Bucket provider is initializing. If you want more control over loading screens, useFeature() returns isLoading which you can use to customize the loading experience:

    function LoadingBucket({ children }) {
      const {isLoading} = useFeature("myFeature")
      if (isLoading) {
        return <Spinner />
      }
    
      return children
    }
    
    //-- Initialize the Bucket provider
    <BucketProvider publishableKey={YOUR_PUBLISHABLE_KEY} /*...*/>
      <LoadingBucket>
      {/* children here are shown when loading finishes */}
      </LoadingBucket>
    <BucketProvider>

Hooks

useFeature()

Returns the state of a given features for the current context.

import { useFeature } from "@bucketco/react-sdk";

function StartHuddleButton() {
  const { isLoading, isEnabled, track } = useFeature("huddle");

  if (isLoading) {
    return <Loading />;
  }

  if (!isEnabled) {
    return null;
  }

  return <Button onClick={() => track()} />;
}

useTrack()

useTrack() lets you send custom events to Bucket. Use this whenever a user uses a feature. Create features in Bucket based off of these events to analyze feature usage.

import { useTrack } from "@bucketco/react-sdk";

function StartHuddle() {
  const track = useTrack();
  return (
    <div>
      <button onClick={() => track("Huddle Started", { huddleType: "voice" })}>
        Start voice huddle!
      </button>
    </div>
  );
}

useRequestFeedback()

useRequestFeedback() returns a function that lets you open up a dialog to ask for feedback on a specific feature. See Automated Feedback Surveys for how to do this automatically, without code.

import { useTrackEvent } from "@bucketco/react-sdk";

const requestFeedback = useRequestFeedback();

requestFeedback({
  featureId: "bucket-feature-id",
  title: "How satisfied are you with file uploads?",
});

See https://github.com/bucketco/bucket-javascript-sdk/blob/main/packages/browser-sdk/FEEDBACK.md#manual-feedback-collection for more information on requestFeedback

useSendFeedback()

useSendFeedback() returns a function that lets you send feedback to Bucket. This is useful if you've manually collected feedback and want to send it to Bucket.

import { useSendFeedback } from "@bucketco/react-sdk";

const sendFeedback = useSendFeedback();

sendFeedback({
  featureId: "bucket-feature-id",
  score: 5,
  comment: "Best thing I"ve ever tried!",
});

See https://github.com/bucketco/bucket-javascript-sdk/blob/main/packages/browser-sdk/FEEDBACK.md#manual-feedback-collection for more information on sendFeedback

Content Security Policy (CSP)

See https://github.com/bucketco/bucket-javascript-sdk/blob/main/packages/browser-sdk/README.md#content-security-policy-csp for info on using Bucket React SDK with CSP

License

MIT License

Copyright (c) 2024 Bucket ApS