question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide Context.currentValue

See original GitHub issue

Now 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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
stephenhcommented, Sep 28, 2019

Cool, that sounds good. Thanks!

0reactions
stephenhcommented, Oct 7, 2019

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found