React Props
JS
S
JavaScriptA component either holds data (has state) or receives data through its props.
1import React from 'react';
2import PropTypes from 'prop-types';
3
4const HrefSample = (props) => {
5 // console.log(props.children);
6 return (
7 <a href={props.href}> {props.text}</a>
8 )
9}
10
11HrefSample.propTypes = {
12 href: PropTypes.string,
13 text: PropTypes.string
14}
15
16HrefSample.defaultProps = {
17 href: 'www.claudioteixeira.com',
18 text: 'anoher cool website'
19}
20
21export default HrefSample;
22
23// ================================================================================================================================
24// From another component template
25{/* passing props */}
26<HrefSampleComponent text="woooww"/>
27<HrefSampleComponent href="coderecipes.org" text="woooww again"/>Created on 2/11/2019