E-mail : support@tech2now.in

What is the difference between .ts and .tsx?

Both file extensions are used for Typescript. Which we used in frameworks like React.

The only difference in both is that .tsx supports JSX (JavaScript XML)content.

Java Script XML is a syntax extension for JavaScript that allows you to write UI components in a declarative way. It’s commonly used for defining the structure and behavior of user interface elements.

Example Code for .tsx

import React from ‘react’

interface IGreeting {

  name: string

}

const Greeting: React.FC<IGreeting> = ({ name }) => {

  return <div>Hi, {name}!</div>

}

export default Greeting