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

fix(rum-react): memoizing function component to avoid unmount #742

Closed
wants to merge 3 commits into from

Conversation

cauemarcondes
Copy link

No description provided.

@vigneshshanmugam vigneshshanmugam changed the title Memoizing function component to avoid unmount fix(rum-react): memoizing function component to avoid unmount Apr 8, 2020
@vigneshshanmugam
Copy link
Member

jenkins run the tests please

@@ -40,6 +41,45 @@ function isReactClassComponent(Component) {
return !!(prototype && prototype.isReactComponent)
}

const getMemoizedApmComponent = memoize((Component, apm, name, type) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgieselaar WDYT about memoize a function that returns a Component? I'm not sure about it. I need to do it to avoid creating a new ApmComponent every time a change happens in the URL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a memory leak I think. I would at least tie it to the lifecycle of a container (e.g. by using getDerivedStateFromProps). I think you also might be able to rewrite this to a component that takes apm, name and type as props, and then you don't need memoization at all.

}

componentDidMount() {
ApmComponent = React.useCallback(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of hooks is available we can use useCallBack to memoize the component.

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

Successfully merging this pull request may close these issues.

3 participants