Closed kamarajuPrathi closed 5 years ago
PropTypes.oneOfType([TestType1, TestType2])
will validate that, assuming both of those are PropTypes.shape
s. What isn't working?
I gave oneoftype , when i am rendering i pass array of object one of type1 or type 2 .
How do i know if the object from the array is of type 1 or type2.
On Thu, Nov 8, 2018, 17:08 Jordan Harband <notifications@github.com wrote:
PropTypes.oneOfType([TestType1, TestType2]) will validate that, assuming both of those are PropTypes.shapes. What isn't working?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/facebook/prop-types/issues/238#issuecomment-437189652, or mute the thread https://github.com/notifications/unsubscribe-auth/AYaVI9gD55oX9TSEMEnpqO2fMp7yqixKks5utLlmgaJpZM4YVppB .
In the propTypes, do you need to?
PropTypes aren't for runtime branching; in your render path you'd need a separate mechanism to distinguish the two objects.
Can I Check Proptype.shape(prop) instanceOf PropTypeCreated?
no.
I have a Proptype as mentioned below
PropTypes.arrayOf(PropTypes.oneOfType([ TestType1, TestType2, ]))
where TestType1 and TestType2 are two(objects) Proptypes of shape .
I render based on the object i receive , whether its Type1 or Type2 .
how do i validate whether the object i recieved is of Type1 or Type2 ?