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
The `WebChatContainer` function component is intended to make it as easy as possible to include web chat in your React application. To use, you simply need to render this component anywhere in your application and provide the [web chat configuration options object](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-configuration#configurationobject) as a prop.
39
41
40
42
```javascript
@@ -50,28 +52,62 @@ const webChatOptions = {
50
52
// Use the onBeforeRender or onAfterRender prop instead.
51
53
};
52
54
53
-
// Include this if you want to get debugging information.
55
+
// Include this if you want to get debugging information from this library. Note this is different than
56
+
// the web chat "debug: true" configuration option which enables debugging within web chat.
You can use the `onBeforeRender` or `onAfterRender` props to get access to the instance of web chat if you need call instance methods later. This example renders a button that toggles web chat open and is only rendered after the instance has become available.
// Make the instance available to the React components.
95
+
setInstance(instance);
96
+
97
+
// Do any other work you might want to do before rendering. If you don't need any other work here, you can just use
98
+
// onBeforeRender={setInstance} in the component above.
99
+
}
100
+
```
101
+
102
+
### Custom responses
103
+
61
104
This component is also capable of managing custom responses. To do so, you need to pass a `renderCustomResponse` function as a prop. This function should return a React component that will render the content for the specific message for that response. You should make sure that the `WebChatContainer` component does not get unmounted in the middle of the life of your application because it will lose all custom responses that were previously received by web chat.
@@ -103,15 +139,10 @@ Note that this component will call the [web chat render](https://web-chat.global
103
139
| Attribute | Required | Type | Description |
104
140
|-----------|----------|---------|-------------|
105
141
| config | Yes | object | The [web chat configuration options object](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-configuration#configurationobject). Note that any `onLoad` property will be ignored. If this prop is changed and a new object provided, then the current web chat will be destroyed and a new one created with the new object. |
106
-
|
107
142
| instanceRef | No | MutableRefObject | A convenience prop that is a reference to the web chat instance. This component will set the value of this ref using the `current` property when the instance has been created. |
108
-
|
109
143
| onBeforeRender | No | function | This is a callback function that is called after web chat has been loaded and before the `render` function is called. This function is passed a single argument which is the instance of web chat that was loaded. This function can be used to obtain a reference to the web chat instance if you want to make use of the instance methods that are available. |
110
-
|
111
144
| onAfterRender | No | function | This is a callback function that is called after web chat has been loaded and after the `render` function is called. This function is passed a single argument which is the instance of web chat that was loaded. This function can be used to obtain a reference to the web chat instance if you want to make use of the instance methods that are available. |
112
-
|
113
145
| renderCustomResponse | No | function | This function is a callback function that will be called by this container to render custom responses. If this prop is provided, then the container will listen for custom response events from web chat and will generate a React portal for each event. This function will be called once during component render for each custom response event. This function takes two arguments. The first is the [custom response event](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-events#customresponse) that triggered the custom response. The second is a convenience argument that is the instance of web chat. The function should return a `ReactNode` that renders the custom content for the response. |
0 commit comments