-
Notifications
You must be signed in to change notification settings - Fork 49.5k
Description
Do you want to request a feature or report a bug?
feature
What is the current behavior?
The current behavior requires end users to use createContext
in the module scope. To my understanding, it's not currently possible to use a default value derived from the state of a component (a stateful Provider in my case).
This StackOverflow post hits the issue right on IMO.
I feel like this is the classic use case for replacing Redux, and it doesn't work out of the box with static types.
I think it's quite telling that react-redux
is doing something similar here in their PR to move to React 16 context. I would expect the default value to be this.state
of the Provider component instead of null
.
My knowledge of React internals is naive, but I didn't see anyone else bringing up this issue.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
What is the desired behavior?
Maybe a JSX API for context creation? I imagine it's not quite that simple.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.3+