Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls to Intercom('update') should be placed in effect not in render method #74

Open
Poky85 opened this issue Sep 11, 2019 · 2 comments

Comments

@Poky85
Copy link

Poky85 commented Sep 11, 2019

When ReactIntercom props changes, Intercom('update') method gets called with new values.

In ReactIntercom v1 update method is called in componentWillReceiveProps lifecycle method.
https://github.com/nhagen/react-intercom/blob/master/src/index.js#L59

In ReactIntercom v2 update method is called directly in render.
https://github.com/nhagen/react-intercom/blob/2.0/src/react-intercom.ts#L69

Side effects in React should be called after component is rendered. Otherwise render performance is affected.

Based on my profiling calling an update takes tens of miliseconds.
image

In version 1 Intercom('update') should be called in componentDidMount().

In version 2 Intercom('update') should be called in useEffect()

@Poky85 Poky85 changed the title Calls to Intercom('update') should be used in effect not in render method Calls to Intercom('update') should be placed in effect not in render method Sep 11, 2019
@tomdohnal
Copy link

I believe this is causing this: Intercom not initialized yet warning.
Would you be interested in a PR with a fix @nhagen ?

@ChristianJacobsen
Copy link

This repo is fairly dead, @tomdohnal.

If you look at the convo in #73 you can follow our discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants