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
|footer | boolean|indicates if Intercom should be automatically booted. If `true` no need to call `boot`, the `IntercomProvider` will call it for you| false| false|
85
-
|startIndex| number | Start index to indicate the wizard to start at the given step. Defaults to| false||
86
-
|header| React.ReactNode | Header that is shown above the active step| false||
87
-
|footer| React.ReactNode | Footer that is shown below the active stepstep | false ||
88
-
| children | React.ReactNode | Each child component will be treated as an individual step
81
+
| name | type | description | required | default |
Used to retrieve all methods bundled with Intercom. These are based on the official [Intercom docs](https://developers.intercom.com/installing-intercom/docs/javascript-api-attributes-objects). Some extra methods were added to improve convenience.
129
+
Used to retrieve all methods and props bundled with the Wizard.
119
130
120
-
Make sure `IntercomProvider` is wrapped around your component when calling `useIntercom()`.
131
+
Make sure `Wizard` is wrapped around your component when calling `useWizard`.
121
132
122
-
**Remark** - You can't use `useIntercom()` in the same component where `IntercomProvider` is initialized.
133
+
**Remark** - You can't use `useWizard` in the same component where `Wizard` is used.
| boot | (props?: IntercomProps) => void | boots the Intercom instance, not needed if `autoBoot` in `IntercomProvider` is `true`|
129
-
| shutdown | () => void | shuts down the Intercom instance |
130
-
| hardShutdown | () => void | same functionality as `shutdown`, but makes sure the Intercom cookies, `window.Intercom` and `window.intercomSettings` are removed. |
131
-
| update | (props?: IntercomProps) => void | updates the Intercom instance with the supplied props. To initiate a 'ping', call `update` without props |
132
-
| hide | () => void | hides the Messenger, will call `onHide` if supplied to `IntercomProvider`|
133
-
| show | () => void | shows the Messenger, will call `onShow` if supplied to `IntercomProvider`|
134
-
| showMessages | () => void | shows the Messenger with the message list |
135
-
| showNewMessages | (content?: string) => void | shows the Messenger as if a new conversation was just created. If `content` is passed, it will fill in the message composer |
136
-
| getVisitorId | () => string | gets the visitor id |
137
-
| startTour | (tourId: number) => void | starts a tour based on the `tourId`|
138
-
| trackEvent | (event: string, metaData?: object) => void | submits an `event` with optional `metaData`|
All the Intercom default attributes/props are camel cased (`appId` instead of `app_id`) in `react-use-intercom`, see [IntercomProps](src/types.ts) to see what attributes you can pass to `boot` or `update`. Or check the Intercom [docs](https://developers.intercom.com/installing-intercom/docs/javascript-api-attributes-objects)
211
-
to see all the available attributes/props.
212
-
213
-
**Remark** - all the listed Intercom attributes [here](https://developers.intercom.com/installing-intercom/docs/javascript-api-attributes-objects) are snake cased, in `react-use-intercom` are these camel cased.
214
-
215
-
#### Custom attributes
216
-
217
-
Still want to pass custom attributes to Intercom? Whether `boot` or `update` is used, you can add your custom properties by passing these through `customAttributes` in the `boot` or `update` method.
218
-
219
-
**Remark** - the keys of the `customAttributes` object should be snake cased (this is how Intercom wants them). They are rawly passed to Intercom.
It's recommended to put the shared components in the `header` or `footer` in the `Wizard` to avoid duplication.
241
197
242
198
## Examples
199
+
Go to [examples](https://github.com/devrnt/react-use-wiard/tree/master/examples) to check see some examples
243
200
244
-
Go to [examples](https://github.com/devrnt/react-use-intercom/tree/master/examples) to check out some integrations (Gatsby, NextJS...).
245
-
246
-
## TypeScript
247
-
248
-
All the possible pre-defined options to pass to the Intercom instance are typed. So whenever you have to pass [IntercomProps](src/types.ts), all the possible properties will be available out of the box.
249
-
These props are `JavaScript` 'friendly', so [camelCase](https://en.wikipedia.org/wiki/Camel_case). No need to pass the props with [snake_cased](https://en.wikipedia.org/wiki/Snake_case) keys.
250
-
251
-
**Remark** - if you want to pass custom properties, you should still use [snake_cased](https://en.wikipedia.org/wiki/Snake_case) keys.
252
-
253
-
## Troubleshoot
254
-
255
-
- I'm seeing `Please wrap your component with IntercomProvider` in the console.
256
-
> Make sure `IntercomProvider` is initialized before calling `useIntercom()`. You only need to initialize `IntercomProvider` once. It is advised to initialize `IntercomProvider` as high as possible in your application tree.
257
-
258
-
> Make sure you aren't calling `useIntercom()` in the same component where you initialized `IntercomProvider`.
259
-
260
-
- I'm seeing `Some invalid props were passed to IntercomProvider. Please check following props: [properties]` in the console.
261
-
> Make sure you're passing the correct properties to the `IntercomProvider`. Check [IntercomProvider](#intercomprovider) to see all the properties.
262
-
> Mind that all the properties in `react-use-intercom` are camel cased, except for the `customAttributes` property in the `boot` and `update` method from `useIntercom`.
263
-
264
-
## Advanced
265
-
266
-
To reduce the amount of re-renders in your React application I suggest to make use of [`useCallback`](https://reactjs.org/docs/hooks-reference.html#usecallback)
267
-
268
-
**TLDR:**`useCallback` will return a memoized version of the callback that only changes if one of the dependencies has changed.
201
+
## Async
269
202
270
-
This can be applied to both the `IntercomProvider` events and the `useIntercom` methods. It depends on how many times your main app gets re-rendered.
203
+
You can connect an async step handler to a step as well. Make sure to make to either pass an async function or return a promise (async) function:
The `isLoading` of `useWizard` will indicate the loading state of the step when calling `nextStep`. If no errors are thrown the wizard will go to the next step, so no need to call this manually. If an error is thrown in the conencted function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your connected function).
294
224
295
-
constHomePage= () => {
296
-
const { boot } =useIntercom();
225
+
If an async function is connected the `isLoading` of `useWizard` will indicate the loading state of the function.
Since `react-use-wizard` is focused to manage the logic of a wizard doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest (https://www.framer.com/motion/)[framer-motion].
302
229
303
-
return<button onClick={bootWithProps}>Boot with props</button>;
304
-
};
305
-
```
230
+
Checkout this (https://github.com/devrnt/react-use-wizard/blob/docs/readme/example/components/animatedStep.tsx)[example] to see an animation to a step can be added.
0 commit comments