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

@dynatrace-sdk/react-hooks

v0.6.0

Published

The `@dynatrace-sdk/react-hooks` library provides a seamless way to interact with Dynatrace platform service clients in React applications. This package leverages hooks to greatly simplify the use of Dynatrace services within React. For detailed informati

Downloads

681

Readme

@dynatrace-sdk/react-hooks

The @dynatrace-sdk/react-hooks library provides a seamless way to interact with Dynatrace platform service clients in React applications. This package leverages hooks to greatly simplify the use of Dynatrace services within React. For detailed information, visit our Developer Portal.

npm install @dynatrace-sdk/react-hooks

Simplified data querying from Grail

Traditionally, querying data in Dynatrace involves using the client-query package and managing complex React state. The useDqlQuery hook in this package streamlines this process. The following example showcases how to fetch data with a DQL query:

const { data, error, isLoading } = useDqlQuery({ body: { query: 'fetch logs' } });

This hook is fully compatible with the parameters used in the queryExecute function of the @dynatrace-sdk/client-query package.

For instance, to limit the number of results returned:

const { data, error, isLoading, refetch } = useDqlQuery(
  {
    body: {
      query: 'fetch logs',
      maxResultRecords: 2000,
    },
  },
  { autoFetch: false, autoFetchOnUpdate: false },
);

You can delay the execution of the query until a user clicks on a button by passing additional options to the hook:

const { data, error, isLoading, refetch } = useDqlQuery({body: {query:  'fetch logs'}, {autoFetch: false}});

function onClickQuery() {
  refetch();
}

You should add appropriate scopes to your app's configuration based on the query type. For more details, refer to the Bucket and table permissions in Grail documentation.

Interacting with documents and app states

Beyond DQL queries, our hooks facilitate interactions with documents and app state. They allow control over immediate or deferred query execution.

const { data, error, isLoading } = useDocument({ id: documentId }, { autoFetch: true });

For creating, updating, or deleting documents or app state, an explicit execute call is necessary:

const { data, execute, error } = useCreateDocument();

function onClickCreateDocument() {
  execute(DOCUMENT_DATA);
}

Depending on your interaction type, add these scopes to your app configuration:

| Function | Scope | | --------------------- | ---------------------------- | | Document read | document:documents:read | | Document write/update | document:documents:write | | Document delete | document:documents:delete | | State read | state:app-states:read | | State write | state:app-states:write | | State delete | state:app-states:delete | | User state read | state:user-app-states:read | | User state write | state:user-app-states:write | | User state delete | state:user-app-states:delete |

Interacting with Settings

Settings can be utilized in the following way:

const { data, error, isLoading } = useSettings({ schemaIds: SETTING_SCHEMA }, { autoFetch: true });

For creating, updating, or deleting settings, an explicit execute call is necessary:

const { data, execute, error } = useCreateSettings();

function onClickCreateSettings() {
  execute(SETTING_DATA);
}

Depending on your interaction type, add these scopes to your app configuration:

| Function | Scope | | --------------------- | --------------------------- | | Settings read | app-settings:objects:read | | Settings write/update | app-settings:objects:write | | Settings delete | app-settings:objects:delete |

Simplified Use of Davis® Analyzers

Leveraging Davis® analyzers traditionally involves complex state management and polling logic, alongside the @dynatrace-sdk/client-davis-analyzers package. The useAnalyzer hook in this package makes this process much more straightforward:

const { data, error, isLoading } = useAnalyzer({
  analyzerName: 'dt.statistics.GenericForecastAnalyzer',
  body: {
    timeSeriesData: {
      expression: query,
    },
  },
});

This hook supports all the parameters available in the executeAnalyzer method from the @dynatrace-sdk/client-davis-analyzers package.

To defer the execution of the analyzer until a user action, like a button click, configure the hook with additional options:

const { data, error, isLoading, refetch } = useAnalyzer({
  analyzerName: 'dt.statistics.GenericForecastAnalyzer',
  body: {
    timeSeriesData: {
      expression: query,
    },
  },
  {
    autoFetch: false,
    autoFetchOnUpdate: true,
  }
});

function onExecuteAnalyzer() {
  refetch();
}

In your app's configuration, include the necessary scope:

| Function | Scope | | ------------ | ----------------------- | | Use analyzer | davis:analyzers:execute |

App functions

The useAppFunction hook is the simplest way to call app functions. As the other hooks in this package, it provides state handling for loading and error states:

const { data, error, isLoading } = useAppFunction({ name: 'functionName', data: 'data' });

Sometimes you want to delay the execution of the app function until a user clicks on a button. This can be achieved by passing additional options to the hook:

const { data, error, isLoading, refetch } = useAppFunction(
  { name: 'functionName', data: 'data' },
  { autoFetch: false, autoFetchOnUpdate: false },
);

function onClick() {
  refetch();
}