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
How to use React-Bootstrap component?
Loop inside React JSX
onClick Event binding and get event name in ReactJs
Check checkbox is Checked or Unchecked
React JS get Tag Name and Inner Text on Click
React JS onClick event handler
How to render one component in another component in React JS?
3 Different Examples - How State Works in React?
How to use onChange and onClick event in React JS?
React JSX