-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2792,6 +2792,8 @@ function updatePortalComponent( | |
return workInProgress.child; | ||
} | ||
|
||
let hasWarnedAboutUsingNoValuePropOnContextProvider = false; | ||
|
||
function updateContextProvider( | ||
current: Fiber | null, | ||
workInProgress: Fiber, | ||
|
@@ -2806,6 +2808,14 @@ function updateContextProvider( | |
const newValue = newProps.value; | ||
|
||
if (__DEV__) { | ||
if (!('value' in newProps)) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
); | ||
} | ||
} | ||
const providerPropTypes = workInProgress.type.propTypes; | ||
|
||
if (providerPropTypes) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now using undefined and reverted message |
||
} | ||
} | ||
|
||
expect(() => ReactTestUtils.renderIntoDocument(<Component />)).toErrorDev( | ||
'Warning: Failed prop type: The prop `value` is marked as required in ' + | ||
'`Context.Provider`, but its value is `undefined`.\n' + | ||
'`Context.Provider`, but its value is `null`.\n' + | ||
' in Component (at **)', | ||
); | ||
}); | ||
|
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:
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