Imporove propTypes for code readability inside render-page.js - Warning: Failed prop type: The prop alt
is marked as required in MainImage
, but its value is undefined
.
#30406
Unanswered
santhoshnumberone
asked this question in
Help
Replies: 1 comment
-
Your |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I just updated my gatsby to 3.1.0
Would appreciate if anyone could point out how i could resolve this issue.
Gatsby develop
runs fine doesn't popup any warning or error, I even getlocalhost
port.File pointed by the WARNING is
page-render.js
insidepublic
directoryAs soon as I run the local host on my
firefox
I get these WARNINGS
Warning: Failed prop type: The prop
altis marked as required in
MainImage, but its value is
undefined.
Warning: Failed prop type: The prop
altis marked as required in
T, but its value is
undefined.
This is my
header.js
file from where the WARNINGS are being generatedHere's the layout of my webpage for better understanding
I went through this blog 4 Things I Wish I Had Known Before Writing my First React App fourth point specifies why these warning come up
4) propTypes for code readability When looking at a component, it isn’t readily apparent what properties that component is expecting to receive in order to run properly. When writing my first React App, I batted down property errors galore. You could add comments to indicate which properties are required, but listing expected properties using React.PropTypes will provide the same clarity while also reducing the possibility of errors by adding type checking. For example, if your top navigation bar is expecting a user name and a photo, you could write: static propTypes = {name: React.PropTypes.string.isRequired} Then if you run this component without the required properties, you will see an error in the console: Warning: Failed prop type: The prop 'name' is marked as required in 'Nav', but its value is 'undefined'. So, while totally optional, propTypes are an easy way to improve code readability and maintainability.
Here's the complete warning
Environment
gatsby info --clipboard
output from inside my project directoryBeta Was this translation helpful? Give feedback.
All reactions