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

Avoid redefining components during rendering #11

Merged
merged 1 commit into from
Dec 31, 2022

Conversation

muffix
Copy link
Owner

@muffix muffix commented Dec 31, 2022

Motivation

This change avoids the definition of new components in render() calls, but instead moved them out into their own components or memoises the definitions.

If we didn't do that, React would recreate the state of each of these components on every call, which is a performance issue and could lead to inconsistencies if the components have a state that should be preserved.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Jest Unit Test
  • Ran on iOS Simulator
  • Ran on iOS physical device
  • Ran on Android emulator
  • Ran on Android physical device

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional context

This change avoids the definition of new components in `render()` calls,
but instead moved them out into their own components or memoises the
definitions.

If we didn't do that, React would recreate the state of each of these
components on every call, which is a performance issue and could lead to
inconsistencies if the components have a state that should be preserved.
@muffix muffix merged commit d255763 into main Dec 31, 2022
@muffix muffix deleted the avoid-redefining-components branch December 31, 2022 09:30
@muffix muffix added ignore-for-release PRs not to be shown in the relase notes PR: Performance improvement ⚡ and removed ignore-for-release PRs not to be shown in the relase notes labels Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant