Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Is there any way I can get type and if the prop is required from prop-types package? #247

Closed
daiict218 opened this issue Dec 28, 2018 · 1 comment
Labels

Comments

@daiict218
Copy link

I have a React Component whose prop-types I've defined. Whenever I'm logging out the propTypes in React. it logs me out a function which is possibly the validator. I want to print the propType and whether the prop is required or not (e.g. prop1: {required: true, value: 5}) at this point. How can I do that?

class Component extends React.Component {
   constructor(){
     console.log(Component.propTypes.prop1);
   }
}

Component.propTypes = {
    prop1: PropTypes.number.isRequired,
    prop2: PropTypes.string
}
@ljharb
Copy link
Contributor

ljharb commented Feb 21, 2019

Related to #60.

There's no metadata exposed currently, so there's no way to do that.

@ljharb ljharb closed this as completed Feb 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants