How to apply validation on props in reactjs? Apply validation in previously developed example in above question?
Answer / Vijay Kumar
To apply validation on props in a React component, you can use a library like `prop-types`. Here's how you could modify the previous example to include prop validation:nn```javascriptnimport React from 'react';nimport PropTypes from 'prop-types';nnclass MyComponent extends React.Component {n static propTypes = {n name: PropTypes.string.isRequired,n age: PropTypes.number.isRequired,n }nn render() {n return (<div>n {this.props.name} is {this.props.age} years old.n </div>);n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
State the main difference between Pros and State?
How can you share an element in the parsing?
What do you understand by “single source of truth”?
What is the lifecycle methods order in mounting?
How to use forms in reactjs?
How to set state with a dynamic key name?
How to build the React app for production?
What is reactjs-jsx? Explain basic code snippet of jsx with the help of a practical example?
what is the usage of refs and keys used in react?
Can you update props in react?
State the difference between getIntialState() and constructor()?
What is React?