Provide Context.currentValue
See original GitHub issueNow that hooks have an easy, non-HOC, non-renderprop, way of accessing context:
const value = useContext(MyContext);
It’d be great to be able to do the same thing from class components, i.e.:
const value = MyContext.currentValue;
I know there would be caveats like “don’t capture the value” (b/c when the context value changes, you’d want to be sure you’re using the latest currentValue on each render), but hooks also have caveats about usage.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Context - React
Context provides a way to pass data through the component tree without having to pass props down manually at every level. In a...
Read more >How to get the data from React Context Consumer outside the ...
I tested a similar approach, there's a _currentValue and _defaultValue members inside a consumer, but accessing Context.Consumer._currentValue.
Read more >Everything You Need to Know about React Context in 2022 ...
When you consume a context, you will get the value provided by the nearest provider going up the document. If no provider exists...
Read more >React.Context. Context provides a way to pass data… - Medium
The contextType property on a class can be assigned a Context object created by React.createContext() . This lets you consume the nearest current...
Read more >What is React Context And How To Use It? - Pagepro
By the definition, React Context provides us with a possibility to pass data through the component tree, so you don't need to pass...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Cool, that sounds good. Thanks!
@bvaughn FWIW I have the start of this here: https://github.com/stephenh/rfcs/blob/add-context-current-value/text/0000-add-context-current-value.markdown
I just wrote the 1st draft; running it by a few people for edits/clarifications/etc., and then will submit a PR to the rfcs repo. Happy to have feedback before then on it, or just wait until the PR.
Thanks!