I want to centralize proptypes that might contain different properties and be or not required. As an example:
Component A has:
roomData: PropTypes.shape({
roomId: PropTypes.number,
roomType: PropTypes.string,
}).isRequired,
while Component B has:
roomData: PropTypes.shape({
roomId: PropTypes.number.isRequired,
roomType: PropTypes.string.isRequired,
game: PropTypes.shape({
gameId: PropTypes.number.isRequired,
drawDescription: PropTypes.string.isRequired,
}).isRequired,
}),
If both are COMPLETELY the same, I know how to do it. The problem is about them being different.
Since
PropTypes.shapeexpect a plain JS object, you can create an external file where you keep your shapes and use/combine them whenever you need it.It'd be something like
utils/propTypesShapes.js:Then in your components: