import{jsx}from"react/jsx-runtime";import{Fragment}from"react";constIf=({children,condition})=>condition?jsx(Fragment,{children}):undefined;constDisplayData=({data})=>jsx(Fragment,{children:data});constdata=undefined;// The important bit:exportdefaultjsx(If,{condition:data,children:jsx(DisplayData,{data}),});
import{jsx}from"react/jsx-runtime";import{Fragment}from"react";constDisplayData=({data})=>jsx(Fragment,{children:data});constdata=undefined;// The important bit:exportdefaultdata?jsx(DisplayData,{data}):undefined;
With If you always call jsx with DisplayData passing data, without If you only do that call if data exists, if not you don't do anything.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes, a good example of how it works
If you understand the underlying code for React, then this is no surprise. When you write:
You're actually writing this:
Compared to doing it with a ternary like this:
That's like writing this:
With
Ifyou always calljsxwithDisplayDatapassingdata, withoutIfyou only do that call ifdataexists, if not you don't do anything.