This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { PropTypes } from 'prop-types'; | |
class User extends React.Component { | |
render() { | |
return ( | |
<div> | |
<p>User Name: {this.props.name}</p> | |
<p>Age: {this.props.age}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PropTypes from 'prop-types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save prop-types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Welcome = ({name = 'Roei', lastName = 'Berkovich'}) => { | |
return (<div>{`Hi ${firstName} ${lastName}`}!</div>) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Welcome = ({name = 'Roei', lastName = 'Berkovich'}) => { | |
return (<div>{`Hi ${firstName} ${lastName}`}!</div>) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Welcome(props) { | |
return <h1>Hello, {props.name}</h1>; | |
} | |
Welcome.defaultProps = { | |
name: 'Roei' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Welcome extends React.Component { | |
static defaultProps = { | |
name: 'Roei' | |
} | |
render() { | |
return <h1>Hello, {this.props.name}</h1>; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Welcome extends React.Component { | |
render() { | |
return <h1>Hello, {this.props.name}</h1>; | |
} | |
} | |
Welcome.defaultProps = { | |
name: 'Roei' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//class example | |
class Welcome extends React.Component { | |
render() { | |
return <h1>Hello, {this.props.name}</h1>; | |
} | |
} | |
//function example | |
function Welcome(props) { | |
return <h1>Hello, {props.name}</h1>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useRef } from "react"; | |
import ReactDOM from "react-dom"; | |
function App() { | |
const [count, setCount] = useState(0); | |
const isFirstRun = useRef(true); | |
useEffect(() => { | |
if (isFirstRun.current) { | |
//skip firstRun |