InterviewSolution
| 1. |
How To Apply Validation On Props In Reactjs? |
|
Answer» When the application is running in development mode, React will automatically check for all props that we set on components to MAKE sure they must right correct and right data type. For instance, if we SAY a component has a Message prop which is a string and is required, React will automatically check and warn if it gets invalid string or number or boolean OBJECTS. For PERFORMANCE reasons this check is only done on dev environments and on PRODUCTION it is disabled so that rendering of objects is done in fast manner . Warning messages are generated easily using a set of predefined options such as:
When the application is running in development mode, React will automatically check for all props that we set on components to make sure they must right correct and right data type. For instance, if we say a component has a Message prop which is a string and is required, React will automatically check and warn if it gets invalid string or number or boolean objects. For performance reasons this check is only done on dev environments and on production it is disabled so that rendering of objects is done in fast manner . Warning messages are generated easily using a set of predefined options such as: |
|