Using conditional if in react I have the following code working fine:
rowData is an object and I want to display download button only if the completePathName is not null and hence I did the following which is working fine. I am wondering if I can improve the following code in some manner or the conditional if that I have used is fine?
buttonTemplate = (rowData: any, column: any)  =&gt; {
        //if(typeof rowData !=='undefined' &amp;&amp; typeof rowData.completePathName !=='undefined'){
        if(rowData.completePathName === null){
            return (
            
              console.log(&quot;Inside first return  - testing rowData:&quot;),
              console.log(rowData),
              console.log(rowData.completePathName),
                &lt;div style={{textAlign: 'center', width: '6em'}}&gt;
                        &lt;span&gt;
                            &lt;Button type='button' icon=&quot;pi pi-pencil&quot; style={{marginRight: '5px'}} onClick={(e) =&gt; this.handleClick(rowData, e)} tooltip='Edit'/&gt;
                            &lt;Button icon=&quot;pi pi-trash&quot; style={{marginRight: '5px'}} tooltip='Delete' /&gt;
                            
                        &lt;/span&gt;
                &lt;/div&gt;
            );

        }
        else {
            return (
                
                console.log(&quot;Inside second return  - testing rowData:&quot;),
                console.log(rowData),
                console.log(rowData.completePathName),
            
                &lt;div style={{textAlign: 'center', width: '6em'}}&gt;
                        &lt;span&gt;
                            &lt;Button type='button' icon=&quot;pi pi-pencil&quot; style={{marginRight: '5px'}} onClick={(e) =&gt; this.handleClick(rowData, e)} tooltip='Edit'/&gt;
                            &lt;Button icon=&quot;pi pi-trash&quot; style={{marginRight: '5px'}} tooltip='Delete' /&gt;
                            &lt;Button icon=&quot;pi pi-download&quot; tooltip='Download' /&gt;
                            
                        &lt;/span&gt;
                &lt;/div&gt;
            );

        }
       
    }
The only thing that changes in the JSX is the download button, so it'd be more appropriate to use conditional rendering when the JSX comes to that line to decide whether you need to render the last button or not:
const ButtonTemplate = (rowData: any) =&gt; (
    &lt;div style={{textAlign: 'center', width: '6em'}}&gt;
        &lt;span&gt;
            &lt;Button type='button' icon=&quot;pi pi-pencil&quot; style={{marginRight: '5px'}} onClick={(e) =&gt; this.handleClick(rowData, e)} tooltip='Edit'/&gt;
            &lt;Button icon=&quot;pi pi-trash&quot; style={{marginRight: '5px'}} tooltip='Delete' /&gt;
            {
              rowData.completePathName !== null &amp;&amp;
              &lt;Button icon=&quot;pi pi-download&quot; tooltip='Download' /&gt;
            }
        &lt;/span&gt;
    &lt;/div&gt;
);

Other notes:

Since you don't use the column parameter, you should remove it entirely

Using any defeats the whole point of using TypeScript, since it effectively disables type-checking for that expression - if you can give proper types to things, it'll make your life a whole lot easier. Consider figuring out how you can type rowData. It may look something like:
rowData: {
  completePathName: string | null
}

(or something similar - just for an example)

If you want to be able to call this as a component, give it an upper-case name: ButtonTemplate, not buttonTemplate. That'll let you do
&lt;ButtonTemplate {...{ rowData, column }} /&gt;

to render it.

You have a lot of inline styles, which makes the JSX harder to read. Consider separating out the style into CSS instead. With Sass, you could give the container a class of buttons-container, and then do:
.buttons-container {
    text-align: center;
    width: 6em;
    button:not([tooltip=&quot;Download&quot;]) {
        margin-right: 5px;
   }
}

and remove all the inline styles from the JSX.