You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: add KnockGuideLocationSensor page, plus a few guide edits (#1206)
* add a page for KnockGuideLocationSensor, along with a few guide edits
* example viz, copy edits
---------
Co-authored-by: Scoti Dodson <scoti@Mac.lan>
Copy file name to clipboardExpand all lines: content/in-app-ui/guides/render-guides.mdx
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Once you've [created a guide](/in-app-ui/guides/create-guides), you'll need to r
9
9
10
10
## Fetching guides
11
11
12
-
You can fetch guides using Knock's client-side SDKsor by directly calling the [guides API](/api-reference/users/guides).
12
+
There are two ways to fetch and render guides: using Knock's client-side SDKs, which provide built-in state management and helper methods, or by directly calling the [guides API](/api-reference/users/guides) to build a custom implementation. Our [step-by-step React example](/in-app-ui/react/headless/guide) demonstrates how to incorporate the SDK's guide provider into your application and render guide components to your users.
13
13
14
14
### Client-side SDKs
15
15
@@ -53,17 +53,16 @@ Knock exposes a set of client SDKs that provide helpers and logic to make it eas
53
53
54
54
#### Key SDK resources
55
55
56
-
When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks:
56
+
When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks for React:
57
57
58
58
-[**KnockGuideProvider**](/in-app-ui/react/sdk/components/knock-guide-provider). Provider component that fetches guides and manages guide state.
59
59
-[**useGuide**](/in-app-ui/react/sdk/hooks/use-guide). Hook to fetch a single guide by type or key.
60
60
-[**useGuides**](/in-app-ui/react/sdk/hooks/use-guides). Hook to fetch multiple guides.
61
61
-[**useGuideContext**](/in-app-ui/react/sdk/hooks/use-guide-context). Hook to access the guide client for advanced use cases.
62
62
63
63
<Callout
64
-
emoji="🚧"
64
+
type="info"
65
65
title="Additional SDK support."
66
-
bgColor="blue"
67
66
text={
68
67
<>
69
68
We're working on adding guides support to more of our client SDKs. Please
@@ -98,9 +97,9 @@ When multiple guides exist for a single `type` (e.g, a generic "Banner" componen
98
97
99
98
<AccordionGroup>
100
99
<Accordiontitle="When should I use useGuide vs useGuides?">
101
-
The [`useGuide`](/in-app-ui/react/sdk/hooks/use-guide) hook fetches a single guide at a time. This is ideal for components that should only display one guide, like a banner or modal that occupies a specific location in your UI.
100
+
The [`useGuide`](/in-app-ui/react/sdk/hooks/use-guide) hook returns a single guide at a time, subject to eligibility criteria, throttling rules, and ordering. This is ideal for components that should only display one guide, like a banner or modal that occupies a specific location in your UI.
102
101
103
-
The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or more guides, subject to eligibility criteria. This is useful for components that can display multiple guides at once, like a list of changelog cards or announcements in a sidebar.
102
+
The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or more guides, subject to eligibility criteria, in the configured order. This is useful for components that can display multiple guides at once, like a list of changelog cards or announcements in a sidebar. The `useGuides` hook is designed to return multiple guides, so it does not apply throttling rules.
104
103
105
104
</Accordion>
106
105
<Accordiontitle="How do I render multiple guides in a single component?">
@@ -116,8 +115,8 @@ The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or mor
116
115
<div>
117
116
{guides.map((guide) => (
118
117
<divkey={guide.key}>
119
-
<h3>{guide.step.content.title}</h3>
120
-
<p>{guide.step.content.body}</p>
118
+
<h3>{guide.steps[0].content.title}</h3>
119
+
<p>{guide.steps[0].content.body}</p>
121
120
</div>
122
121
))}
123
122
</div>
@@ -142,5 +141,5 @@ The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or mor
142
141
143
142
To see which guides are actually eligible to be rendered, check the `entries` array in the API response, which contains only the guides that match all criteria for the current user and context.
helper component inside <code>KnockGuideProvider</code> to facilitate
78
+
evaluating activation rules based on route changes.
79
+
</>
80
+
}
81
+
/>
82
+
>
67
83
</Step>
68
84
<Step title="Setup a custom message type.">
69
85
If you're not using one of our pre-built message types, you'll need to set up a custom message type. You can learn more about how to do this in our [message types](/in-app-ui/message-types/create-message-types) documentation.
A React helper component intended for use with select supported frameworks, such as [Next.js](https://nextjs.org/) and [Tanstack Router](https://tanstack.com/router/), for detecting route changes.
2
+
3
+
Activation rules for guides are evaluated as a user's location changes in your application and, by default, [KnockGuideProvider](/in-app-ui/react/sdk/components/knock-guide-provider) listens for location change events from the global `window` object (enabled via the `trackLocationFromWindow` prop). However, modern frameworks often provide their own first class router APIs for detecting and reacting to route changes, which often works better and more reliably.
4
+
5
+
Two important notes to keep in mind when implementing `KnockGuideLocationSensor`:
6
+
7
+
1. The import path is specific to the corresponding framework (e.g., `@knocklabs/react/next` for Next.js).
8
+
2.`KnockGuideLocationSensor` must be placed inside `KnockGuideProvider`.
9
+
10
+
## Usage
11
+
12
+
### Next.js
13
+
14
+
```jsx title="Next.js implementation of KnockGuideLocationSensor."
0 commit comments