question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing React.PropTypes.oneOfShape operator

See original GitHub issue
import 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:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
probablyupcommented, Aug 4, 2015
React.PropTypes.arrayOf(
    React.PropTypes.oneOfType(
        [
            React.PropTypes.shape({}),
            React.PropTypes.shape({})
        ]
    )
)

(just making @JohnyDays example more legible)

0reactions
JohnyDayscommented, Aug 6, 2015

Glad it worked out! 🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found