-
Notifications
You must be signed in to change notification settings - Fork 7.8k
16.3 release blog draft #587
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
444896e
Initial draft for 16.3 release blog
bvaughn 141de66
Wording changes in response to PR feedback
bvaughn ce57928
Added entry for createRef API
bvaughn da29d89
Added note about string ref API to strict mode section
bvaughn a55480b
Small wording nit
bvaughn 935d2a1
Minor edits in response to PR feedback
bvaughn ab62e88
Formatted example
bvaughn 08d444e
Wordsmithing in response to PR feedback
bvaughn 5a1d653
Incorporated Sophie's PR feedback
bvaughn 8494428
Added example of before/after context API
bvaughn c08533a
Removed context-before example
bvaughn 33ff167
Wordsmith nit
bvaughn c09a284
Added React.createRef doc
trueadm ee78358
address feedback
trueadm b049931
revised content as per PR feedback
trueadm 9bc1932
updated line numbers
trueadm 6627687
Describe what a ref is at the top of the doc
0e7243f
Merge intro paragraphs
c07a6b0
Merge pull request #1 from alexkrolick/create-ref-patch
trueadm 7b02740
Create "Accessing refs" section above specific examples
d7b34d4
Merge pull request #2 from alexkrolick/create-ref-patch-2
trueadm 8075ce2
Make the callback example more similar to the new API
96fe82c
Declare setRef method outside render
alexkrolick 96b10a7
Grammar
alexkrolick 962ef9a
Highlight deprecation notice
alexkrolick 4b939d2
~~All things considered~~
alexkrolick 04c7f16
Wording
alexkrolick b1adba0
Recommend old API when applicable
alexkrolick 9b869fa
Update leading sentence
alexkrolick 566406e
Add docs for new Context API (R16.3)
alexkrolick a89e6b8
Added link to context API docs
bvaughn 5e0901d
Merge pull request #3 from alexkrolick/create-ref-patch-3
trueadm 3f304b9
Merge pull request #4 from alexkrolick/create-ref-patch4
trueadm f6e5d65
Fixed off-by-one line highlights.
bvaughn 6e35810
Merge branch 'master' into 16.3-release-blog-post
bvaughn 6a1ba97
Moved 16.3 release date arbitrarily forward
bvaughn 1de2e33
Fixed links
bvaughn c7a61e6
Imported StrictMode docs (and examples) from PR #596
bvaughn fecb153
Merge pull request #1 from trueadm/create-ref
bvaughn 866ef01
Prettier
bvaughn 12d7c16
Updated createRef 'value' attributes to 'current'
bvaughn e5bf594
Unnest callback ref example code
alexkrolick 2f97f48
Fixed docs
bvaughn a357b64
Added React.forwardRef to 16.3 release blog post
bvaughn a937c46
Typo fixes
bvaughn 201fcad
Added React.forwardRef to API and docs
bvaughn 2b1de01
Rebuild Netlify
bvaughn 22d0ec1
Updated forwardRef example to use named function
bvaughn fe033f6
Added StrictMode to docs sidenav
bvaughn f14f147
Renamed ref in example
bvaughn 5d5a5d2
StrictMode title => Strict Mode
bvaughn 2ead10e
Update nav
gaearon 29d6592
Update React.Component reference to show deprecations and new lifecycles
bvaughn 0780f72
Reorganize examples & legacy docs
alexkrolick a5022da
Add in-page TOC
alexkrolick fe3d0a4
Typo
alexkrolick 808e5bd
Rephrase and reorganize
alexkrolick de22379
Syntax tweaks
alexkrolick 291b2fd
Wording tweaks
alexkrolick 6aa1995
Add solution to motivation problem
alexkrolick 7c6688c
Highlight createContext()
alexkrolick b49f99b
Highlight whole createContext() call
alexkrolick dbce488
Merge pull request #3 from alexkrolick/new-context-api
bvaughn 2f9b77a
16.4 -> 16.x
bvaughn e9ae68f
remove confusing {}
alexkrolick 53d604f
~deprecated~ legacy
alexkrolick fec6d6c
Add mutliple contexts example
alexkrolick 7b5764f
Add ref forwarding, lifecycle examples
alexkrolick 0d32f18
Kill highlight
alexkrolick 7db107b
+ "default value" comment
alexkrolick da091e6
Add note about how changes are determined
alexkrolick 6eb29a1
Combine basic examples
alexkrolick 9f54997
Update highlights
alexkrolick 4e1282e
Add to "when to use context"
alexkrolick f588bd6
Update "legacy" wording
alexkrolick ccc1f26
Replace "deprecated" with "legacy" for now
alexkrolick 3af89c9
Merge pull request #4 from alexkrolick/context-tweaks
bvaughn 01c2691
Replaced cWRP in forwardRef example with cDU
bvaughn f5d5139
Formatted a Note
bvaughn 5864093
Updated context-in-lifecycles example
bvaughn d66d3a2
Updated TODO for later
bvaughn ef23c49
Updated multi-context example to show more indirection
bvaughn b25276a
Updated forward-refs example to use class component
bvaughn c41bb29
Added DevTools name consideration to forwardRef examples
bvaughn 1ead060
17 -> future version
alexkrolick d58c892
+ "same algo"
alexkrolick e689824
Add notes about composing multiple contexts
alexkrolick 509b126
Explain context in lifecycle a bit more
alexkrolick fe84e09
Explain why you need forwardRef
alexkrolick 9e4442a
typo
alexkrolick 3c44882
Use function keyword
alexkrolick f9225e2
Remove propTypes
alexkrolick fb8e9e8
kill class props
alexkrolick 6919801
Use functional component
alexkrolick c9d50e3
Remove lib link
alexkrolick 7ac0712
Updated 16.3 blog post to account for getSnapshotBeforeUpdate lifecycle
bvaughn 920b4f4
Replace divs with some fake components
alexkrolick 349446d
Add caveats section
alexkrolick b0e8604
Prettier
alexkrolick 8437e37
Fix syntax
alexkrolick 587ad93
Merge pull request #5 from alexkrolick/16.3-release-blog-post
bvaughn f11a149
Added DevTools naming consideration to React.forwardRef reference doc…
bvaughn bd06bbc
Added context HOC example to reference
bvaughn b7b97c0
Merge branch 'master' into 16.3-release-blog-post
bvaughn 6d77836
Linked to async blog post
bvaughn e5cf31a
Renamed blog post
bvaughn a29098e
Merge branch 'master' into 16.3-release-blog-post
bvaughn 57eb7cc
Tweaked message about what goes into state
bvaughn 28b2b76
Tweaked state-and-lifecycle wording more
bvaughn 691cd45
Added inline child function caveat to Context docs
bvaughn 032576c
Prettier
bvaughn 797a792
Revert "Prettier"
bvaughn 3a36a40
Revert "Added inline child function caveat to Context docs"
bvaughn e5ca13e
Cross-link to async update post
bvaughn 992a756
Missing 'we'
bvaughn 5a587d1
Tweaked link to Context API
bvaughn ac1d767
Fixed link
bvaughn aa9810f
Fixed some links and improved a recommendation
bvaughn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,9 @@ Accepts a `value` prop to be passed to Consumers that are descendants of this Pr | |
|
|
||
| A React component that subscribes to context changes. | ||
|
|
||
| Requires a [function as a child](/docs/render-props.html#using-props-other-than-render). The function receives the current context value and returns a React node. All consumers are re-rendered whenever the Provider value changes. Changes are determined by comparing the new and old values using the same algorithm as [`Object.is`](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Description). (This can cause some issues when passing objects as `value`: see [Caveats](#caveats).) | ||
| Requires a [function as a child](/docs/render-props.html#using-props-other-than-render). The function receives the current context value and returns a React node. The function should be created inline, as shown in the example above, rather than being bound to the instance or otherwise cached. (Refer to the see [Caveats](#consumer-inline-function-as-a-child) section below for more.) | ||
|
|
||
| All consumers are re-rendered whenever the Provider value changes. Changes are determined by comparing the new and old values using the same algorithm as [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Description). (This can cause some issues when passing objects as `value`: see [Caveats](#objectis).) | ||
|
|
||
| > Note | ||
| > | ||
|
|
@@ -134,6 +136,16 @@ One issue with the render prop API is that refs don't automatically get passed t | |
|
|
||
| ## Caveats | ||
|
|
||
| ### `Consumer` Inline Function as a Child | ||
|
|
||
|
||
| As an optimization to avoid doing unnecessary work, React currently stops rendering when it sees children that are equal to the most recently rendered children. This applies to the [function as a child](/docs/render-props.html#using-props-other-than-render) pattern used by `Consumer` as well which can cause unexpected behavior in some situations: | ||
| `embed:context/consumer-cached-function-as-a-child.js` | ||
|
|
||
| To avoid this scenario, we recommend declaring the child function inline: | ||
| `embed:context/consumer-inline-function-as-a-child.js` | ||
|
|
||
| ### `Object.is` | ||
|
|
||
| Because context uses reference identity to determine when to re-render, there are some gotchas that could trigger unintentional renders in consumers when a provider's parent re-renders. For example, the code below will re-render all consumers every time the Provider re-renders because a new object is always created for `value`: | ||
|
|
||
| `embed:context/reference-caveats-problem.js` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Example extends React.Component { | ||
|
||
| // This method will be called when the context value changes, | ||
| // But not when the props value changes! | ||
| renderValue = value => { | ||
| return ( | ||
| <div> | ||
| Context value:{value}. Props value:{this.props.counter} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| render() { | ||
| return <Ctx.Consumer>{this.renderValue}</Ctx.Consumer>; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Example extends React.Component { | ||
|
||
| render() { | ||
| // The inline function will be called when the context value changes, | ||
| // And when the props value changes! | ||
| return ( | ||
| <Ctx.Consumer> | ||
| {value => ( | ||
| <div> | ||
| Context value:{value}. Props value:{this.props.counter} | ||
| </div> | ||
| )} | ||
| </Ctx.Consumer> | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before Caveats, I think we should also add a section that explains how to create a higher order component for consuming context. This is a common sentiment and I think we should proactively address it: https://twitter.com/DankoKozar/status/977469702204162048?s=20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context comes before the Higher-Order Components reference page, but I'll cross link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, cyclical dependencies are pretty much unavoidable in the "Advanced" section