Best Practices

Best practices for v5 app development based on the Location 5.0 app.


Code Organization

Use Feature-Based Folder Structure

src/
├── views/              # One folder per view
│   ├── portfolio/
│   ├── details/
│   └── settings/
├── components/         # Shared components
│   ├── location-card/
│   └── stats-summary/
└── forms/             # Form components
    └── location-form/

Keep Files Small and Focused

  • One component per file

  • Co-locate styles with components

  • Extract complex logic into custom hooks/ utility functions


Component Patterns

Use registerUI() for Views

Centralize API Calls in services.ts

Use UXP Components


Styling

Use BEM Naming with App Prefix

Always Use Theme Variables


Data Fetching

Use Hooks for Data Loading

Handle Loading and Error States


TypeScript

Define Types

Use Proper Props Interfaces


Configuration

Keep configuration.yml Clean

Use Meaningful IDs


Performance

Use React.memo for Heavy Components

Avoid Unnecessary Re-renders


Error Handling

Always Handle Errors

Show User-Friendly Messages


Testing During Development

Use Watch Mode

Test in Actual iviva App

  • Don't rely on standalone index.html

  • Always test in the actual iviva application

  • Verify navigation works

  • Check permissions


Localization

Use $L() for All Text

Organize Translation Keys


Quick Checklist

Before committing code:


Common Pitfalls to Avoid

❌ Using registerWidget() for pages ❌ Hardcoding colors instead of theme variables ❌ Not handling loading/error states ❌ Hardcoded text without localization ❌ Creating custom components instead of using UXP components ❌ Testing only in standalone mode (index.html) ❌ Not organizing files by feature ❌ Mixing concerns in single files


Summary

Follow these practices for clean, maintainable v5 apps:

  1. Use feature-based organization

  2. Register views as UI, not widgets

  3. Centralize API calls in services.ts

  4. Use BEM naming with app prefix

  5. Always use theme variables

  6. Use UXP hooks for data fetching

  7. Handle all states (loading, error, success)

  8. Localize all text

  9. Test in actual iviva app

  10. Keep configuration.yml clean and organized


See Location 5.0 app (/apps/iviva.dx/Location/5.0/) for working examples of all these practices.

Last updated