How to use a dynamic array with `PropTypes.oneOf`?

458 views Asked by At

Since oneOf only accepts array, I decided to define a checker function and written the following code, however, it does not work.

const mapping = {
  foo: ["aaa", "bbb"],
  bar: ["ccc", "ddd"]
}

MyComponent.propTypes = {
  variant: (props, propName, componentName) => {
    if(props[propName]) PropTypes.oneOf(mapping[props.type])
  },
  tag: PropTypes.string
};

What is the right way to use another built-in checker function in a custom checker function? Is it possible?

0

There are 0 answers