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', |
gaearon
Jun 30, 2020
Member
Let's reword this a bit:
The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?
Let's reword this a bit:
The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?
charlie1404
Jun 30, 2020
Author
Contributor
Thanks for the message 😅 .
Thanks for the message
charlie1404
Jun 30, 2020
Author
Contributor
updated
updated
if (!hasWarnedAboutUsingNoValuePropOnContextProvider) { | ||
hasWarnedAboutUsingNoValuePropOnContextProvider = true; | ||
console.error( | ||
'The prop `value` is required in `Context.Provider`, have you misspelled it', |
gaearon
Jun 30, 2020
Member
Same
Same
@@ -263,13 +263,13 @@ describe('ReactContextValidator', () => { | |||
|
|||
class Component extends React.Component { | |||
render() { | |||
return <TestContext.Provider />; | |||
return <TestContext.Provider value={null} />; |
gaearon
Jun 30, 2020
Member
Make this value={undefined}
instead and you won't need to change the message.
Make this value={undefined}
instead and you won't need to change the message.
charlie1404
Jun 30, 2020
Author
Contributor
now using undefined and reverted message
now using undefined and reverted message
Small nits and this is good to go. |
f4097c1
into
facebook:master
Coolio, thanks. |
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