create a function in react code example

Example 1: react functional components

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

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 <button onClick={this.handleClick.bind(this)} value="Click me" />;
    }
}

Example 3: react function component

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}