-
Notifications
You must be signed in to change notification settings - Fork 137
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
Conversation
jenkins run the tests please |
@@ -40,6 +41,45 @@ function isReactClassComponent(Component) { | |||
return !!(prototype && prototype.isReactComponent) | |||
} | |||
|
|||
const getMemoizedApmComponent = memoize((Component, apm, name, type) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
No description provided.