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
How to pass an Argument to a Method used inside JSX expression?
How to pass properties from parent component to child component in React JS?
Example of React Bootstrap Datatable
Create Functional Component using ES6 Arrow Syntax
3 Different Examples - How State Works in React?
How to use arrow function in React stateless components?
Integrate Bootstrap with ReactJS Application
Working with Forms, Inputs and onChange Events in ReactJs
React JS Count number of checkboxes are checked
Create React App