How to perform computation inside expression using ternary operator?
Expressions can be used for any computation, below example uses the ternary operator to determine whether length and breadth are equal or not. Based on that identify it is square or rectangle and also calculate area of that.
Example
import React, { Component } from 'react';
const length = 10, breadth = 20;
class App extends Component {
render = () =>
<span class="d-block p-2 bg-dark text-white">
Area of { length == breadth ? "Sqaure" : "Rectangle" }: { length * breadth}
</span>
}
export default App;
Most Helpful This Week
React Components
React JS Count number of checkboxes are checked
How to show hide component on Click in React JS?
Example of React Bootstrap Datatable
Create Functional Component using ES6 Arrow Syntax
How to pass data from child component to its parent in ReactJS?
How to pass properties from parent component to child component in React JS?
How to pass an Argument to a Method used inside JSX expression?
React JS onClick event handler
How to render one component in another component in React JS?