Missing React.PropTypes.oneOfShape operator
See original GitHub issueimport React from 'react';
let timeShape,
placeholderShape;
timeShape = React.PropTypes.shape({
type: React.PropTypes.oneOf(['time']).isRequired,
date2: React.PropTypes.number.isRequired,
url: React.PropTypes.string.isRequired,
position: React.PropTypes.number.isRequired
});
placeholderShape = React.PropTypes.shape({
type: React.PropTypes.oneOf(['placeholder']).isRequired,
position: React.PropTypes.number.isRequired
});
export default React.createClass({
propTypes: {
times: React.PropTypes.arrayOf(React.PropTypes.oneOfShape([timeShape, placeholderShape])).isRequired
},
render: function () {
return <div />;
}
});
There is no way to validate whether times
is an array where is each property if oneOfShape
. Whats even worst, if you use oneOfType
in the latter example, it produces no error and does not validate the data as expected.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Allow different types of PropTypes for one prop - Stack Overflow
I have a component that receives a prop for its size. The prop can be either a string or a number ex: "LARGE"...
Read more >How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >How To Use PropTypes In React - Web Dev Simplified Blog
PropTypes is a tool in React that lets you validate the structure and type of all your props and if there are any...
Read more >prop-types | Yarn - Package Manager
You can use prop-types to document the intended types of properties passed to components. React (and potentially other libraries—see the checkPropTypes() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
(just making @JohnyDays example more legible)
Glad it worked out! 🚀