Skip to content

Commit c018b06

Browse files
committed
Add doc
1 parent 23ebdc1 commit c018b06

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

docs/HOOKS.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,32 +253,57 @@ To set the avatar for the user, change the props passed to Web Chat via style op
253253

254254
## `useBuildRenderActivityCallback`
255255

256-
> New in 4.19.0.
256+
> New in 4.19.0. Read more about this at [MIDDLEWARE.md](./MIDDLEWARE.md).
257257
258258
<!-- prettier-ignore-start -->
259259
```ts
260260
useBuildRenderActivityCallback():
261-
(request: { activity: WebChatActivty }) =>
262-
(props: { children?: never }) =>
263-
{
264-
render: (overridingProps?: Partial<Props> | undefined) => ReactElement | null
265-
};
261+
(request: { activity: WebChatActivity }}) =>
262+
(
263+
(props: { children?: never }) => ReactElement | null
264+
) | undefined;
266265
```
267266
<!-- prettier-ignore-end -->
268267

269-
The hook will return a function, when called with request and props, will return a render function to render the activity.
268+
The hook will return a function, when called with request and props, will return a render function to render the activity, or `undefined` if the activity should not be rendered.
269+
270+
The following code snippet demonstrates rendering of activity using `useBuildRenderActivityCallback()`.
271+
272+
```ts
273+
function MyComponent({ activity }: { readonly activity: WebChatActivity }) {
274+
const renderActivity = useBuildRenderActivityCallback();
275+
const renderFunction = renderActivity({ activity });
276+
277+
return renderFunction && <Fragment>{renderFunction({})}</Fragment>;
278+
}
279+
```
270280

271-
<!-- TODO: [P*] Finish this. -->
281+
### `<ActivityPolymiddlewareProxy>`
272282

273-
### ActivityPolymiddlewareProxy
283+
`<ActivityPolymiddlewareProxy>` is a simpler way to render an activity.
274284

275285
<!-- prettier-ignore-start -->
276286
```tsx
277-
<ActivityPolymiddlewareProxy activity={} />
287+
const ActivityPolymiddlewareProxy: ComponentType<{ readonly activity: WebChatActivity }>;
278288
```
279289
<!-- prettier-ignore-end -->
280290

281-
<!-- TODO: [P*] Finish this. -->
291+
The following code demonstrates using `<ActivityPolymiddlewareProxy>` to render an activity.
292+
293+
<!-- prettier-ignore-start -->
294+
```tsx
295+
function MyComponent({ activity }: { readonly activity: WebChatActivity }) {
296+
return <ActivityPolymiddlewareProxy activity={activity} />;
297+
}
298+
```
299+
<!-- prettier-ignore-end -->
300+
301+
Differences between `useBuildRenderActivityCallback()` and `<ActivityPolymiddlewareProxy>`:
302+
303+
- `useBuildRenderActivityCallback()` allows precise render control
304+
- Developers can control how the render function is being used and what to do if the polymiddleware decided not to render the activity
305+
- `<ActivityPolymiddlewareProxy>` always render an element
306+
- If the polymiddleware decided not to render the activity, it will always render an empty/headless element (returning `false`)
282307

283308
## `useByteFormatter`
284309

0 commit comments

Comments
 (0)