'Proptypes that allows array or null

I have a prop that received an array of string or null value, how to specify a react propType for that prop?

i.e.,

myprop = ["hello"]
myprop = null

are allowed for prop value

I tried

prop: PropTypes.oneOfType([
                [null],
                PropTypes.arrayOf(PropTypes.string)])

this syntax doesn't seem to be allowed.



Solution 1:[1]

Just use:

prop: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string)])

By default, all prop types aren't required (i.e. allow null or undefined) unless you pop a .isRequired on the end of them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matias Seguel