facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Custom validator inside a shape #222

Closed smercadomx closed 5 years ago

smercadomx commented 6 years ago

Is there a way to get all the props in a custom validator defined inside a shape:

  static propTypes = {
    prop1: PropTypes.string,
    myShape: PropTypes.shape({
      prop2: (props, propName, componentName) => {
        // props only contains the props declared inside the shape
        console.log(props);
      },
      prop3: PropTypes.string
    })
  }
ljharb commented 6 years ago
myShape: (allProps, ...rest) => {
  return PropTypes.shape({
    prop2: (props, propName, componentName) => {
      console.log(allProps, props);
    },
  })(allProps, ...rest);
},
smercadomx commented 6 years ago

great, thanks!