-
Notifications
You must be signed in to change notification settings - Fork 46.3k
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
Added warning to <Context.Provider> in case no value prop is provided #19054
Added warning to <Context.Provider> in case no value prop is provided #19054
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1603910:
|
did like the name of the code sandbox 🤣.
wondering why cannot just update deps it old one 😞 |
Question, would making the |
@heath-freenome
But pointing to prop types gave me a better message, thanks for that, updating it now. |
React just recently removed all runtime dependencies to |
if (!hasWarnedAboutUsingNoValuePropOnContextProvider) { | ||
hasWarnedAboutUsingNoValuePropOnContextProvider = true; | ||
console.error( | ||
'The prop `value` is required in `Context.Provider`, have you misspelled it', |
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.
Let's reword this a bit:
The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?
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.
Thanks for the message 😅 .
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.
updated
if (!hasWarnedAboutUsingNoValuePropOnContextProvider) { | ||
hasWarnedAboutUsingNoValuePropOnContextProvider = true; | ||
console.error( | ||
'The prop `value` is required in `Context.Provider`, have you misspelled it', |
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.
Same
@@ -263,13 +263,13 @@ describe('ReactContextValidator', () => { | |||
|
|||
class Component extends React.Component { | |||
render() { | |||
return <TestContext.Provider />; | |||
return <TestContext.Provider value={null} />; |
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.
Make this value={undefined}
instead and you won't need to change the message.
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.
now using undefined and reverted message
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.
Small nits and this is good to go.
Coolio, thanks. |
What if I don't want to send a For example:
This is throwing me the error: Can we make it optional? |
Summary
This PR aims to add a fix for #19020
packages/react-reconciler/src/ReactFiberBeginWork.new.js
packages/react-reconciler/src/ReactFiberBeginWork.old.js
In feature flag saw
const enableNewReconciler = false
but still cannot jump to any solid conclusions hence added in both.Test Added
packages/react-reconciler/src/__tests__/ReactNewContext-test.js
test to detect warning.Tests Updated Reason
As now
<Context.Provider>
now throws a warning if value prop is not given, and hence updated the ones which were not having value prop to havenull
now.Points to be discussed
cc @brunogonzales @heath-freenome