Skip to content

Why connect wrap Component using ContextToUse.Provider instead of Consumer ? #1875

Answered by markerikson
FaiChou asked this question in Q&A
Discussion options

You must be logged in to vote

Because each connected component should only re-render when its nearest connected ancestor component has rendered. This is necessary to ensure that mapState always has access to the latest props from the immediate parent component. To do that, connect triggers a cascade of additional "update" notifications. The only way for this to work is to override the subscription field in the context value object, and doing that requires re-rendering the same Context.Provider component with an updated value.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by FaiChou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants