Platform specific import component in react native with typescript

One way of doing it, which is a bit annoying, is creating a declaration file with the same name.

component
- component.d.ts   <---
- component.android.tsx
- component.ios.tsx

then

import { file } from "../group/file";

Update:
Another way of doing it is just omit the extension for one of them, then typescript will pick up the default one.

  • component.tsx
  • component.android.tsx

Android will pick up the specific android file, and iOS will default to normal one.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)