Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize JSX Attribute Syntax for className Update what-is-tia.js #419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xbryer
Copy link

@0xbryer 0xbryer commented Nov 16, 2024

Description:

This PR addresses an outdated syntax issue in JSX attribute handling, specifically for className concatenation. The legacy approach of concatenating strings using the + operator has been replaced with modern, more readable template literals (```).

Example of outdated syntax:

className={"mb-3 button button-" + heroData.buttons[0].class}

Updated syntax:

className={`mb-3 button button-${heroData.buttons[0]?.class}`}

Why is this important?

  1. Improved Readability: Template literals provide a cleaner and more intuitive way to work with dynamic strings in JSX.
  2. Error Reduction: The modern syntax is less prone to errors, especially when working with complex string interpolations.
  3. Best Practices: Aligns the codebase with modern React/JSX conventions, improving maintainability and reducing the technical debt over time.
  4. Future-Proofing: Adopting ES6+ standards ensures compatibility with modern JavaScript tooling and development environments.

Changes Made:

  • Updated all occurrences of string concatenation for className to use template literals.
  • Verified the usage of optional chaining (?.) where applicable to avoid runtime errors for undefined values.

Testing:

  • Tested all affected components locally to ensure correct rendering.
  • Checked for any broken styles or functionality due to the syntax update.

Before:

className={"mb-3 button button-" + heroData.buttons[0].class}

After:

className={`mb-3 button button-${heroData.buttons[0]?.class}`}

Additional Notes:

This change is small but impactful for maintaining code quality and readability. Adopting modern syntax ensures the project aligns with current best practices.

Refactor: Modernize JSX Attribute Syntax for className Concatenation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant