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

@bem-react/di: re-render all components inside withRegistry #551

Closed
yarastqt opened this issue Mar 31, 2020 · 0 comments
Closed

@bem-react/di: re-render all components inside withRegistry #551

yarastqt opened this issue Mar 31, 2020 · 0 comments
Assignees

Comments

@yarastqt
Copy link
Member

Проблема

На каждом рендере мы создаем вновь реестры, из-за чего все вложенные компоненты рендерятся по новой (этот поинт описан в докуменетации реакта).

const providedRegistries = { ...contextRegistries }
for (let i = 0; i < registries.length; i++) {
const registry = registries[i]
const overrides = contextRegistries[registry.id]
// eslint-disable-next-line no-nested-ternary
providedRegistries[registry.id] = registry.overridable
? overrides
? registry.merge(overrides)
: registry
: registry && overrides
? overrides.merge(registry)
: registry
}
return (
<RegistryProvider value={providedRegistries}>

Пример — https://codepen.io/sartem/pen/wvaNjpO

Решение

Можно обернуть RegistryResolver в memo, либо советуют в документации, хранить значения контекста в локальном стейте компонента.

@yarastqt yarastqt self-assigned this Mar 31, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 1, 2020
artems added a commit to artems/bem-react that referenced this issue Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant