1.0.3 • Published 10 months ago

@mdb-devx/papercuts-widget v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Papercuts Widget

import { Widget } from "@mdb-devx/papercuts-widget";

The Widget component allows end users to submit reports directly to Papercuts with the following metadata:

  • The application name, provided by the appName prop
  • The current URL

An example:

// somewhere.tsx
import { Widget } from "@mdb-devx/papercuts-widget";

function Somewhere() {
  return <Widget appName="myapp" />;
}

Props

import type { ComponentProps } from "react";

export type WidgetProps = Pick<ComponentProps<"section">, "className"> & {
  appName: string; // application name to attach to reports
  onError?: (res: Response) => Promise<void> | void; // Optional callback
  onSuccess?: (res: Response) => Promise<void> | void; // Optional callback
  postUrl?: string; // Optional, if POST requires a proxy
};

Custom Metadata

The WidgetDefaultsProvider component is optional, but provides a React context to set custom metadata attached to Papercuts reports:

// _app.tsx
import type { PropsWithChildren } from "react";
import { Widget, WidgetDefaultsProvider } from "@mdb-devx/papercuts-widget";

export function App({ children }: PropsWithChildren) {
  return (
    <WidgetDefaultsProvider>
      {children}

      <Widget appName="myapp" />
    </WidgetDefaultsProvider>
  );
}

Somewhere else:

// component.tsx
import { useEffect } from "react";
import { useSetWidgetDefaults } from "@mdb-devx/papercuts-widget";

export default function Component() {
  const setWidgetDefaults = useSetWidgetDefaults();

  useEffect(() => {
    const newMetadata = {
      // define your new metadata here
    };

    setWidgetDefaults({ metadata: newMetadata });
  }, [setWidgetDefaults]);

  // rest of your component
}

See your feedback...

To see the reports submitted via this widget, visit Papercuts Search.

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.1-0

11 months ago

1.0.0

11 months ago

1.0.0-7

11 months ago

1.0.0-6

11 months ago

1.0.0-5

11 months ago

1.0.0-4

11 months ago

1.0.0-3

11 months ago

1.0.0-1

11 months ago