Articles → REACT.JS → Using variables and methods in react.js

Using variables and methods in react.js






Sample code




import React, { Component } from 'react';
import ReactDOM from 'react-dom'

class Message extends Component {
    message = "Hello world";

    getMessage() {
        return "Hello world from method";
    }

    render() {
        return (
            <table>
                <tr>
                    <td>
                        {this.message}
                    </td>
                </tr>
                <tr>
                    <td>
                        {this.getMessage()}
                    </td>
                </tr>
            </table>);
    }

}
ReactDOM.render(<Message/>, document.getElementById('root'));





Output


Picture showing the output of variables and methods in react.js

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 2, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250