Is there a way in React to change a prop type to avoid TypeErrors?

I’m wondering if there’s a way to change a prop type if the one that is being passed isn’t of the type expected.

For example, if my component expects to receive an object (Using PropTypes or using TypeScript notation), but an array is passed, that array should be converted into an object (It can be an empty object).

Is there a way to archive this?

1 thought on “Is there a way in React to change a prop type to avoid TypeErrors?”

Leave a Comment