Using this keyword access component properties and methods
The this keyword refers to the component instance and required to specify the properties and method defined by the component. Here, dimension refers to the state property created in constructor.
Example
import React, { Component } from 'react';
const length = 20, breadth = 10;
function shape() {
return length == breadth ? "Sqaure" : "Rectangle";
}
function area() {
return length * breadth;
}
class App extends Component {
render = () =>
<span class="d-block p-2 bg-dark text-white">
Area of { shape() }: { area() }
</span>
}
export default App;
Most Helpful This Week
onMouseDown and onMouseUp Event handling in ReactJs
React JS onClick event handler
How to render one component in another component in React JS?
State and Props in React
Create React App
React Elements
How to render raw HTML content in React JS?
Check checkbox is Checked or Unchecked
Display JSON Data in React JS
React Components