1 / 8

Conditional Rendering

Condition Rendering is used to represent output by applying conditions in code with three different approached which is fetched while rendering of code. Suppose we have a code with following condition-:<br><br>

ducathub
Download Presentation

Conditional Rendering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WELCOME TO DUCAT INDIA Conditional Rendering 7070905090 info@ducatindia.com

  2. Conditional Rendering Condition Rendering is used to represent output by applying conditions in code with three different approached which is fetched while rendering of code. Suppose we have a code with following condition-: If user is logged in then display ‘you’re welcome’ if not logged in then display ‘Welcome guest’

  3. For Example we put conditions on code with three different approaches. • First Approach-: If-Else is first approach. Using If-Else in JSX is not valid so use it outside JSX code as-:

  4. Second Approach Elements Variable- Use JavaScript variables to store elements as-: • Third Approach Ternary conditional operator- Here conditional operator is used. It can be easily used in JSX as-:

  5. Fourth Approach Short Circuit Operator- This Approach is just specific case of ternary conditional operator. You must render something or nothing using short circuit approach.

  6. Prevent rendering with Null Advantage of returning “null” instead of empty element is that performance will be improved of the app because react wont Unmount component to replace.

  7. React Element Variables If you don’t want more than one return statement so to avoid writing return Statement again and again use a variable to store the JSX elements and only initialize it when condition is “true”

  8. THANK YOU 7070905090 info@ducatindia.com

More Related