Created
June 27, 2021 17:29
-
-
Save OlivierJM/3df183f6666772cae2ff2744a4bdda97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PropTypes from 'prop-types' | |
export default function Card({ title, mainText, color, colors, details }) { | |
return ( | |
<div> | |
<h2 style={{ color }}>{title}</h2> | |
<p>{mainText}</p> | |
{colors.map((colorItem) => ( | |
<span key={colorItem}>{colorItem}</span> | |
))} | |
<br /> | |
{details.id} | |
<br /> | |
<br /> | |
</div> | |
) | |
} | |
Card.defaultProps = { | |
color: '#000000', | |
} | |
Card.propTypes = { | |
title: PropTypes.string.isRequired, | |
color: PropTypes.string, | |
mainText: PropTypes.string.isRequired, | |
colors: PropTypes.arrayOf( | |
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | |
).isRequired, | |
details: PropTypes.shape({ | |
id: PropTypes.number, | |
width: PropTypes.string, | |
}).isRequired, | |
} | |
// to dynamically use your components ==> rendering data from the server | |
// declaring the types for your props | |
// props ==> component parameters | |
// proptypes help define the types for your props | |
// (title) => string | |
/** | |
* | |
* @param {Number} x any number | |
* @param {Number} y any given | |
* @returns Number | |
*/ | |
function sum(x, y) { | |
return x + y | |
} | |
sum(2, 34) | |
sum(2, 6) | |
sum(2, 2) | |
sum(6, 34) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Deewiliams documentation for proptypes can be found here https://reactjs.org/docs/typechecking-with-proptypes.html#gatsby-focus-wrapper