Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ const HomePage = () => {
## Playground
Example playground to showcase the functionalities of `react-use-intercom`.

### useIntercom
[https://devrnt.github.io/react-use-intercom/#/useIntercom](https://devrnt.github.io/react-use-intercom/#/useIntercom)

### useIntercom (with Intercom tour)
[https://devrnt.github.io/react-use-intercom/#/useIntercomTour](https://devrnt.github.io/react-use-intercom/#/useIntercomTour)

## TypeScript
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.
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.
Expand Down
3 changes: 1 addition & 2 deletions example/modules/useIntercom/useIntercomTour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const RawUseIntercomStartPagePage = () => {
const handleBoot = React.useCallback(() => boot({ name: 'Russo' }), [boot]);

const handleStartTour = React.useCallback(() => {
// TODO: update tour id
startTour(122198);
startTour(124247);
}, [startTour]);

return (
Expand Down
11 changes: 11 additions & 0 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IntercomContextValues, IntercomProviderProps } from './contextTypes';
import { IntercomAPI } from './intercom';
import { IntercomProps, RawIntercomBootProps } from './types';
import { mapIntercomPropsToRawIntercomProps } from './mappers';
import { isEmptyObject } from './utils';

export const IntercomProvider = ({
appId,
Expand All @@ -15,7 +16,17 @@ export const IntercomProvider = ({
onHide,
onShow,
onUnreadCountChange,
...rest
}: IntercomProviderProps) => {
if (!isEmptyObject(rest))
logger.log(
'error',
[
'some invalid props were passed to IntercomProvider. ',
`Please check following props: ${Object.keys(rest).join(', ')}.`,
].join(''),
);

const [isBooted, setIsBooted] = useState(autoBoot);

if (!window.Intercom) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isEmptyObject = (obj: object) =>
Object.keys(obj).length === 0 && obj.constructor === Object;