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
Click to Enlarge