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

Render launcher conditionally based on the route #40

Open
davidbsoares opened this issue May 25, 2023 · 1 comment
Open

Render launcher conditionally based on the route #40

davidbsoares opened this issue May 25, 2023 · 1 comment

Comments

@davidbsoares
Copy link

Is is possible to render the contact form button conditionally?

@ravinggenius
Copy link

I had to figure this out today. Here's what I came up with:

// app.tsx near the root

import Zendesk, { ZendeskAPI } from "react-zendesk";

<Zendesk
  defer
  onLoaded={() => {
    ZendeskAPI("webWidget", "hide");
  }}
  zendeskKey={ZENDESK_KEY}
/>
// shared-layout.tsx or single-one-off-page.tsx

import { ZendeskAPI } from "react-zendesk";

useEffect(() => {
  ZendeskAPI("webWidget", showZendeskSupport ? "show" : "hide");
}, []);
  1. Mount <Zendesk /> near your app root. Optionally use onLoaded to hide the widget by default.
  2. Use useEffect() to show/hide the widget on pages as needed.
  3. Optionally if you have a layout component, you can add a prop (showZendeskSupport) to avoid duplicating the useEffect() everywhere.

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

No branches or pull requests

2 participants