react-intercom icon indicating copy to clipboard operation
react-intercom copied to clipboard

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

Open Poky85 opened this issue 5 years ago • 2 comments

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 avatar Sep 11 '19 15:09 Poky85

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

tomdohnal avatar Jun 24 '20 08:06 tomdohnal

This repo is fairly dead, @tomdohnal.

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

ChristianJacobsen avatar Jun 24 '20 09:06 ChristianJacobsen