Skip to content

Commit

Permalink
Update jsx-no-constructed-context-values.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kud committed Jan 28, 2021
1 parent 4881bae commit eb78605
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/rules/jsx-no-constructed-context-values.md
Expand Up @@ -23,7 +23,7 @@ return (
Examples of **correct** code for this rule:

```
const foo = useMemo(() => {foo: 'bar'}, []);
const foo = useMemo(() => ({foo: 'bar'}), []);
return (
<SomeContext.Provider value={foo}>
...
Expand All @@ -34,4 +34,4 @@ return (
## Legitimate Uses
React Context, and all its child nodes and Consumers are rerendered whenever the value prop changes. Because each Javascript object carries its own *identity*, things like object expressions (`{foo: 'bar'}`) or function expressions get a new identity on every run through the component. This makes the context think it has gotten a new object and can cause needless rerenders and unintended consequences.

This can be a pretty large performance hit because not only will it cause the context providers and consumers to rerender with all the elements in its subtree, the processing for the tree scan react does to render the provider and find consumers is also wasted.
This can be a pretty large performance hit because not only will it cause the context providers and consumers to rerender with all the elements in its subtree, the processing for the tree scan react does to render the provider and find consumers is also wasted.

0 comments on commit eb78605

Please sign in to comment.