React by Ben

JSX Functions

JSX supports user-defined JavaScript functions. Function usage is similar to expression. Let us create a simple function and use it inside JSX.

Example

<script type="text/babel">
   var currentTime = new Date().toTimeString();
   ReactDOM.render(
      <div><p>The current time is {currentTime}</p></div>, 
      document.getElementById('app') 
   );
</script>

Output
Here, getCurrentTime() is used to get the current time, and the output is similar as specified below −

16:37:32 GMT-0700 (Pacific Daylight Time)

Comments

Leave a Comment

All fields are required. Your email address will not be published.