function in functional component react code example

Example 1: functional component react

function Welcome(props) {
  return 

Hello, {props.name}

; } function App() { return (
); } ReactDOM.render( , document.getElementById('root') );

Example 2: defining functions in react

export default class Archive extends React.Component { 

    saySomething(something) {
        console.log(something);
    }

    handleClick(e) {
        this.saySomething("element clicked");
    }

    componentDidMount() {
        this.saySomething("component did mount");
    }

    render() {
        return 

Example 3: create functional component react

import React from 'react'; const App = () => {  const greeting = 'Hello Function Component!';   return ;}; const Headline = ({ value }) =>  

{value}

; export default App;

Example 4: react functional component example

function Greeting(props) {
  
  return 

Hello, {props.name}!

}

Tags:

Misc Example