Skip to content
LaurenMcM749 edited this page Jul 16, 2024 · 2 revisions

Welcome to the amaxa wiki!

Ongoing repository of tips, info, and resources for working with the code.

Marketing website

  1. All images go in the "public" folder. Read more about node's Image component.

TSX and JS are file extensions used in web development, particularly within the context of React applications. They denote different file types and typically imply different programming languages or configurations:

TSX (TypeScript with JSX)

  • Extension: .tsx
  • Language: TypeScript with JSX (JavaScript XML)
  • Usage:
    • Used in React applications where TypeScript is preferred or required for type safety and enhanced development experience.
    • Allows TypeScript to be used alongside JSX syntax, which is a syntax extension for JavaScript often used with React for describing UI components.

Key Points:

  • TypeScript: A superset of JavaScript that adds static typing and other features to the language.
  • JSX: Syntax extension for JavaScript that allows XML/HTML-like structures to be written within JavaScript code, commonly used to define React components.

Example:

// ExampleComponent.tsx
import React from 'react';

type Props = {
  message: string;
};

const ExampleComponent: React.FC<Props> = ({ message }) => {
  return <div>{message}</div>;
};

export default ExampleComponent;

JS (JavaScript)

  • Extension: .js
  • Language: JavaScript
  • Usage:
    • Used traditionally in React applications without TypeScript.
    • Commonly used for scripting, client-side web development, and server-side Node.js applications.

Key Points:

  • JavaScript: The standard programming language for web development.
  • React: Originally developed to use JavaScript, but can also use TypeScript for enhanced type checking and editor support.

Example:

// ExampleComponent.js
import React from 'react';

const ExampleComponent = ({ message }) => {
  return <div>{message}</div>;
};

export default ExampleComponent;

Differences:

  • Type Safety: TSX provides static type checking through TypeScript, helping catch potential errors during development.
  • Development Experience: TypeScript can provide better code editor support, including IntelliSense and type information.
  • Flexibility: JavaScript (JS) is more widely used and understood, but TypeScript (TSX) offers stricter syntax and more robust type system for larger projects or teams requiring stronger guarantees about code correctness.

Choosing Between TSX and JS:

  • TSX: Choose TypeScript with TSX if you prefer or require static type checking, enhanced code editor support, or a more structured approach to JavaScript development.
  • JS: Stick with JavaScript if you prefer simplicity, are working in a small or personal project, or prefer not to introduce the overhead of TypeScript.

In summary, TSX and JS represent different approaches to web development within the React ecosystem, with TSX offering TypeScript's benefits of type safety and JS offering simplicity and familiarity with JavaScript's dynamic typing.