K
K
kirillgenets2019-12-19 13:21:19
Exceptions
kirillgenets, 2019-12-19 13:21:19

How to handle Warnings from prop-types? How to access the result of a type check from a component?

Hello! The task is to do the following: when the props component arrives, if some property does not satisfy the type assigned to it from propTypes, in the UI, instead of the component, display information that an error has occurred.
How to find out from a component that incorrect props came to it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-12-19
@Robur

check their type by hand.
if (typeof stringProp !== 'string') //ah-oh
well, and further according to needs and imagination. If you need to show something else, then you can directly in the render.
or use https://www.npmjs.com/package/prop-types
On a more global level, go to typescript and see all such errors at the time of writing the code, and catch incorrect data at the point of their appearance in the application, and not where they can be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question