Skip to content

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

Description

@Poky85

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions