react function component template 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: 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: functional components

function Welcome(props) {  return 

Hello, {props.name}

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

Tags:

Misc Example