How to pass an Argument to a Method used inside JSX expression?
The expression in below example invokes the shape() and area() method, using the len and bre value as the argument.
Example
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.dimension = {
len: 40,
bre: 50
}
}
shape(l, b) {
return l == b ? "Sqaure" : "Rectangle";
}
area(l, b) {
return l * b;
}
render = () =>
<span class="d-block p-2 bg-dark text-white">
Area of { this.shape(this.dimension.len, this.dimension.bre) }:
{ this.area(this.dimension.len, this.dimension.bre) }
</span>
}
export default App;
Most Helpful This Week
How to set property values using expression?
React JS update Div content on click
React JS Blog CRUD operation
How to use arrow function in React stateless components?
How to render one component in another component in React JS?
How to use createElement in React JS?
Component displays Height and Width on window resize
Check which Radio button is Selected or Clicked
How to use onChange and onClick event in React JS?
Loop inside React JSX