const Camper = (props) => {
return (
<p>{props.name}</p>
)
};
Camper.defaultProps = {name: 'CamperBot'}
Camper.propTypes = { name: PropTypes.string.isRequired}
npm install --save prop-types
import PropTypes from "prop-types";
MyComponent.propTypes = {
name: PropTypes.string,
id: PropTypes.number.isRequired,
img: PropTypes.string
grades: PropTypes.arrayOf(PropTypes.number),
friends: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number,
})
),
list: PropTypes.arrayOf(PropTypes.any),
};
MyComponent.defaultProps = {
img: "https://picsum.phones/200/300",
}
import PropTypes from 'prop-types';
class Greeting extends React.Component {
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
Greeting.propTypes = {
name: PropTypes.string
};
import React from 'react';
import PropTypes from 'prop-types';
const Example = (props) => {
return (
<div>
<p>Some prop: {props.some}</p>
<p>Other prop: {props.other}</p>
</div>
);
};
Example.propTypes = {
some: PropTypes.string.isRequired,
other: PropTypes.number.isRequired
};
export default Example;
// proptypes using class component
Detaljer.PropTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
// proptypes using function component
Detaljer.propTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
type OscarProp = {
children: React.ReactNode;
};
type OscarProp = {
children: React.ReactNode;
};
import PropTypes from 'prop-types'
function HelloWorldComponent({ name }) {
return (
<div>Hello, {name}</div>
)
}
HelloWorldComponent.propTypes = {
name: PropTypes.string
}
export default HelloWorldComponent
itemName.propTypes = {
props: PropTypes.dataType.isRequired
};
//You can now use `PropTypes.elementType`
// to validate for Component type props
import PropTypes from 'prop-types'; // ES6
var PropTypes = require('prop-types'); // ES5 with npm
Code Example |
---|
Css :: linear gradient farthest-corner code css |
Css :: linking in css |
Css :: animate a position css |
Css :: vendor Prefixing |
Css :: center |
Css :: github lottie |
Css :: selector css |
Css :: switch checkbox |
Css :: animation in css |
Css :: how to add images on images css |
Css :: grid all items same height |
Css :: css gradient |
Css :: accent-color |
Css :: inline css not working table odoo 11 |
Css :: react exact path highlight |
Css :: css tutorial point |
Css :: cl image tag width |
Css :: redesign html select |
Css :: css backdrop filter grayscale |
Css :: itemize text indent |
Css :: @keyframes opact |
Css :: Sideways Left Tabs |
Css :: learn golang in a day |
Css :: fusedLocationClient.removeLocationUpdates |
Css :: creating a static flex container with scrolling child element |
Css :: Image not rendering in tailwind css |
Css :: #shadow-root (open) css |
Css :: css text shadow effect |
Css :: como fazer listrada css |
Css :: make td match display flex |