Created
January 2, 2020 19:00
-
-
Save debonx/238441487c9edad4be5f332015554e5b to your computer and use it in GitHub Desktop.
React: Stateless functional component example.
This file contains hidden or 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
// Normal way to display a prop: | |
export class MyComponentClass extends React.Component { | |
render() { | |
return <h1>{this.props.title}</h1>; | |
} | |
} | |
// Stateless functional component way to display a prop: | |
export const MyComponentClass = (props) => { | |
return <h1>{props.title}</h1>; | |
} | |
// Normal way to display a prop using a variable: | |
export class MyComponentClass extends React.component { | |
render() { | |
let title = this.props.title; | |
return <h1>{title}</h1>; | |
} | |
} | |
// Stateless functional component way to display a prop using a variable: | |
export const MyComponentClass = (props) => { | |
let title = props.title; | |
return <h1>{title}</h1>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment