Back to all reviewers

maintain cross-platform API consistency

facebook/react-native
Based on 2 comments
JavaScript

When designing APIs that work across multiple platforms, ensure consistent return types and behavior to avoid breaking changes and maintain a unified developer experience. Use Platform.select() to handle platform-specific implementations rather than hardcoded conditional logic.

API JavaScript

Reviewer Prompt

When designing APIs that work across multiple platforms, ensure consistent return types and behavior to avoid breaking changes and maintain a unified developer experience. Use Platform.select() to handle platform-specific implementations rather than hardcoded conditional logic.

For APIs that need different implementations per platform, structure the code to provide consistent types while allowing platform-specific behavior:

return Platform.select({
  android: this.isLoadedFromFileSystem()
    ? this.drawableFolderInBundle()
    : this.resourceIdentifierWithoutScale(),
  ios: this.isCatalogAsset()
    ? this.assetFromCatalog()
    : this.scaledAssetURLNearBundle(),
  default: this.scaledAssetURLNearBundle()
});

When a platform cannot provide meaningful data, return a consistent placeholder value rather than undefined or void types. For example, if web platforms cannot provide an OS version, return a stable string like โ€œ1000.0.0โ€ to maintain type consistency across all platforms. This prevents breaking changes for consumers who expect consistent API contracts regardless of the underlying platform.

2
Comments Analyzed
JavaScript
Primary Language
API
Category

Source Discussions