Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update examples to use hubspot.serverless for calling app functions #89

Merged
merged 7 commits into from
Dec 20, 2024

Conversation

tamara-at-hubspot
Copy link
Contributor

@tamara-at-hubspot tamara-at-hubspot commented Dec 19, 2024

This change was previously introduced in #49 then reverted in #59, because we did not have product rollout lined up. I'm submitting this change again to finish the swing. We are hoping to have the examples updated and the API officially documented by the end of the month.

Description

  • We are introducing a simpler API, hubspot.serverless, for calling app functions in @hubspot/ui-extensions@0.8.5.
  • Note that the runServerlessFunction way still works.
  • See an example migrating from runServerlessFunction to hubspot.serverless.

This PR is best reviewed by commits.

Usage

With promise syntax:

import { hubspot } from "@hubspot/ui-extensions";

hubspot.extend(() => <Extension />);

const Extension = () => {
  const handleSubmit = () => {
    hubspot
      .serverless("func-name", {
        // options, if any (e.g., propertiesToSend or parameters)
      })
      .then((response) => {
        // handle response, which is the value returned from the function on success
      })
      .catch((error) => {
        // handle error, which is an Error object if the function failed to execute
      });
  };
  return <Button onClick={handleSubmit} label="Click me" />;
}

With async/await syntax:

import { hubspot } from "@hubspot/ui-extensions";

hubspot.extend(() => <Extension />);

const Extension = () => {
  const handleSubmit = async () => {
    try {
      const response = await hubspot.serverless("func-name", {
        // options, if any (e.g., propertiesToSend or parameters)
      });
      // handle response, which is the value returned from the function on success
    } catch (error) {
      // handle error, which is an Error object if the function failed to execute
    };
  };
  return <Button onClick={handleSubmit} label="Click me" />;
}

Copy link
Contributor

@atanasiuk-hubspot atanasiuk-hubspot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants