create function in react component code example

Example 1: class in react

class App extends Component {
    constructor() {
        super()
        this.state = {
            name: "Sally",
            age: 13
        }
    }
    
    render() {
        return (
            

{this.state.name}

{this.state.age} years old

) } }

Example 2: class app extends component syntax

class Welcome extends React.Component {
  render() {
    return 

Hello, {this.props.name}

; } }

Example 3: react functional components

const component = () => {
console.log("This is a functional Component");
}

Example 4: functional components

function Welcome(props) {  return 

Hello, {props.name}

; } const element = ;ReactDOM.render( element, document.getElementById('root') );

Tags:

Misc Example