Skip to content

Commit 4e252f5

Browse files
committed
docs: Minor docs update for hooks
1 parent 4166496 commit 4e252f5

File tree

2 files changed

+14
-43
lines changed

2 files changed

+14
-43
lines changed

docs/examples/custom_hooks.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ keywords: [react, chat, chatbot, chatbotify]
77

88
# Custom Hooks
99

10-
The following is an example for using custom hooks, which allows you to interact with the chatbot functionalities **externally** (i.e. from your own components). The full list of hooks and the functionalities they expose can be found [**here**](/docs/api/hooks). For this example, we'll only be looking at a few hooks such as [**`useAudio`**](/docs/api/hooks#useaudio), [**`useFlow`**](/docs/api/hooks#useflow), [**`useToasts`**](/docs/api/hooks#usetoast) and [**`useNotifications`**](/docs/api/hooks#usenotifications). The hooks are imported within the `MyChatBotWrapper` component which is nested under `ChatBotProvider`.
10+
The following is an example for using custom hooks, which allows you to interact with the chatbot functionalities **externally** (i.e. from your own components). The full list of hooks and the functionalities they expose can be found [**here**](/docs/api/hooks). For this example, we'll only be looking at a few hooks such as [**`useAudio`**](/docs/api/hooks#useaudio), [**`useFlow`**](/docs/api/hooks#useflow), [**`useToasts`**](/docs/api/hooks#usetoast), [**`useNotifications`**](/docs/api/hooks#usenotifications) and [**`useMessages`**](/docs/api/hooks#usemessages). The hooks are imported within the `MyChatBotWrapper` component which is nested under `ChatBotProvider`.
1111

1212
```jsx live noInline title=MyChatBot.js
1313
const MyChatBotWrapper = () => {
1414
const { toggleAudio } = useAudio();
1515
const { restartFlow } = useFlow();
1616
const { showToast } = useToasts();
1717
const { playNotificationSound } = useNotifications();
18+
const { injectMessage } = useMessages();
1819

1920
const settings = {
2021
general: {embedded: true},
@@ -40,6 +41,7 @@ const MyChatBotWrapper = () => {
4041
<ExampleButton onClick={restartFlow} text="Click me to reset the flow!"/>
4142
<ExampleButton onClick={() => showToast("Hello there!")} text="Click me to show a toast!"/>
4243
<ExampleButton onClick={playNotificationSound} text="Click me to play a notification sound!"/>
44+
<ExampleButton onClick={() => injectMessage("Hello I'm an injected message!")} text="Click me to inject a message!"/>
4345
<ChatBot settings={settings} flow={flow}/>
4446
</>
4547
);

src/theme/ReactLiveScope/index.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,24 @@
11
import React from "react";
22
import { GoogleGenerativeAI } from "@google/generative-ai";
3-
import OpenAI from 'openai';
4-
5-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
3+
import OpenAI from "openai";
4+
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
65

76
let ChatBot = null;
8-
let ChatBotProvider = null;
9-
let hooks = {};
10-
let Button = null;
11-
let getDefaultSettings = null
12-
let getDefaultStyles = null;
13-
let useAudio = null;
14-
let useNotifications = null;
15-
let useFlow = null;
16-
let useToasts = null;
7+
let reactChatbotify = {};
178

189
if (ExecutionEnvironment.canUseDOM) {
19-
ChatBot = require("react-chatbotify").default;
20-
hooks = {
21-
ChatBotProvider,
22-
Button,
23-
getDefaultSettings,
24-
getDefaultStyles,
25-
useAudio,
26-
useNotifications,
27-
useFlow,
28-
useToasts
29-
} = require("react-chatbotify");
30-
ChatBotProvider = hooks.ChatBotProvider;
31-
Button = hooks.Button;
32-
getDefaultSettings = hooks.getDefaultSettings;
33-
getDefaultStyles = hooks.getDefaultStyles;
34-
useAudio = hooks.useAudio;
35-
useNotifications = hooks.useNotifications;
36-
useFlow = hooks.useFlow;
37-
useToasts = hooks.useToasts;
10+
const chatbotifyModule = require("react-chatbotify");
11+
ChatBot = chatbotifyModule.default;
12+
reactChatbotify = { ...chatbotifyModule };
13+
delete reactChatbotify.default;
3814
}
3915

4016
const ReactLiveScope = {
4117
React,
4218
ChatBot,
43-
ChatBotProvider,
44-
Button,
45-
getDefaultSettings,
46-
getDefaultStyles,
47-
useAudio,
48-
useNotifications,
49-
useFlow,
50-
useToasts,
19+
...reactChatbotify,
5120
GoogleGenerativeAI,
52-
OpenAI
21+
OpenAI,
5322
};
54-
55-
export default ReactLiveScope;
23+
24+
export default ReactLiveScope;

0 commit comments

Comments
 (0)