Calls to Intercom('update') should be placed in effect not in render method
Opened this issue · 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.
In version 1 Intercom('update')
should be called in componentDidMount()
.
In version 2 Intercom('update')
should be called in useEffect()
I believe this is causing this: Intercom not initialized yet
warning.
Would you be interested in a PR with a fix @nhagen ?
This repo is fairly dead, @tomdohnal.
If you look at the convo in #73 you can follow our discussion.