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

@safe-apps-react-sdk - do not initialize new SafeAppsSDK class on every render #156

Closed
brendanmc6 opened this issue May 8, 2021 · 1 comment

Comments

@brendanmc6
Copy link

brendanmc6 commented May 8, 2021

https://github.com/gnosis/safe-apps-sdk/blob/master/packages/safe-apps-react-sdk/src/index.tsx#L18

This line here means that a new class will be constructed on every component re-render. I'm not sure how expensive that is in reality, but it's an easy fix:

const [sdk] = useState(() => {
  return new SafeAppsSDK(opts)
});

https://reactjs.org/docs/hooks-reference.html#lazy-initial-state

@brendanmc6 brendanmc6 changed the title @safe-apps-react-sdk - do not initialize new SDK class on ever render @safe-apps-react-sdk - do not initialize new SafeAppsSDK class on every render May 8, 2021
@mmv08
Copy link
Member

mmv08 commented May 11, 2021

Thank you! We'll fix it in the next release

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

No branches or pull requests

2 participants